Redis缓存数据库的安装与配置(2)
1.为php安装redis客户端扩展
wget https://github.com/nicolasff/phpredis/archive/master.zip
tar xf phpredis-master.tar.gz -C /usr/src/
cd /usr/src/phpredis-master/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
修改php.ini设置,重启php
#将php.ini配置文件中的extension_dir修改成如下:
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"
echo "extension = redis.so" >> /usr/local/php/lib/php.ini
2. 开发php程序操作redis
[root@redis01 scripts]# cat redis.php
[root@redis01 redis-2.10.1]# python
Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
cat python-redis.py
#/usr/bin/python
from wsgiref.simple_server import make_server
import redis
def get_redis():
r = redis.Redis(host='10.0.0.135',port='6379',password='yunjisuan',db=0)
r.set('name','yunyunyun')
return r.get('name')
def hello_world_app(environ,start_response):
status = '200 OK' #HTTP Status
headers = [('Content-type','text/plain')] #HTTP Headers
start_response(status,headers)
# The returned object is going to be printed
return get_redis()
httpd = make_server('',8000,hello_world_app)
print "Serving on port 8000..."
# Server until process is killed
httpd.serve_forever()