http://redis.io/download
php-redis下载:
https://github.com/nicolasff/phpredis
参考书籍:
https://github.com/JasonLai256/the-little-redis-book/blob/master/cn/redis.md
安装redis:
wget http://redis.googlecode.com/files/redis-2.4.6.tar.gz
tar -zxvf redis-2.4.6.tar.gz
cd redis-2.4.6
make
make install
cp redis.conf /etc/
启动redis:
src/redis-server /etc/redis.conf
开始客户端:
src/redis-cli
关闭redis:
redis-cli shutdown //关闭所有
redis-cli -p 6397 shutdown //关闭6397端口的redis
说明:关闭以后缓存数据会自动dump到硬盘上,硬盘地址见redis.conf中的dbfilename dump.rdb
可能得报错信息:
Warning: no config file specified, using the default config. In order to specify a config file use 'redis-server /path/to/redis.conf'
警告:没有明确的config文件,使用默认配置。为了明确配置文件请使用'redis-server /path/to/redis.conf'
WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
警告:过量使用内存设置为0!在低内存环境下,后台保存可能失败。为了修正这个问题,请在/etc/sysctl.conf 添加一项 'vm.overcommit_memory = 1' ,然后重启(或者运行命令'sysctl vm.overcommit_memory=1' )使其生效。
安装php-redis
cd phpredis
/usr/local/php/bin/phpize #这个phpize是安装php模块的
./configure –with-php-config=/usr/local/php/bin/php-config
make
make install
配置php.ini:
加入extension=redis.so
先要看看有没有extension_dir=/....
重启apache或者nginx
测试代码:
<?php
$redis = new Redis();
$redis->connect('127.0.0.1',6379);
$redis->set('test','hello world!');
echo $redis->get('test');
?>
转自:http://blog.csdn.net/21aspnet/article/details/6960757