作者在 2012-12-15 21:41:26 发布以下内容
-
安装Redis
- wget http://redis.googlecode.com/files/redis-2.6.7.tar.gz
-
tar zxvf redis-.*
cd redis-*
make
make PREFIX=/usr/local/redis install -
mkdir /etc/redis
cp redis.conf /etc/redis/redis.conf
mkdir /var/lib/redis -
vi /etc/redis/redis.conf
#dbfilename dump.rdb #注释掉
logfile /var/log/redis.log #指定log路径
appendonly yes
appendfilename /var/lib/redis/appendonly.aof #指定数据文件路径 -
vi /etc/rc.local
/usr/local/redis/bin/redis-server /etc/redis/redis.conf & #添加这行
重启服务器
-
安装PHP扩展
- wget https://github.com/nicolasff/phpredis/archive/master.zip
-
mv master master.zip
unzip master.zip
cd phpredis-*
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install -
cd /usr/local/php/lib/php/extensions/no-debug-non-zts-*
mv redis.so ../
rm -rf no-debug-non-zts-*
-
vi /usr/local/php/etc/php.ini
extension=redis.so #添加扩展 -
kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid` #重启php
phpinfo(); #查看是否有redis扩展 -
用代码测试
<?php $redis = new Redis(); $redis->connect('127.0.0.1',6379); $redis->set('test','Hello World'); echo $redis->get('test');