1,安装Redis
1.1,下载及安装
wget http://redis.googlecode.com/files/redis-2.6.14.tar.gz
tar -zxvf redis-2.6.14.tar.gz
cd redis-2.6.14
make PREFIX=/data/apps/redis2.6.14 install
mkdir /data/apps/redis2.6.14/etc
cp redis.conf /data/apps/redis2.6.14/etc
1.2,启动Redis
/data/apps/redis2.6.14/bin/redis-server /data/apps/redis2.6.14/etc/redis.conf > /dev/null &
1.3,停止Redis
/data/apps/redis2.6.14/bin/redis-cli -h 127.0.0.1 -p 6379 shutdown
1.4,测试
/data/apps/redis2.6.14/bin/redis-cli
redis 127.0.0.1:6379> set foo bar
OK
redis 127.0.0.1:6379> get foo
"bar"
1.5,可能会出现的错误提示
>>提示1:
make[3]: gcc:命令未找到
>>解决
yum -y install gcc-c++
>>提示2:
在包含自 adlist.c:34 的文件中:
zmalloc.h:50:31: 错误:jemalloc/jemalloc.h:没有那个文件或目录
zmalloc.h:55:2: 错误:#error "Newer version of jemalloc required"
>>解决
make的时候加上 MALLOC=libc 参数
make PREFIX=/data/apps/redis2.6.14 MALLOC=libc install
2,安装phpredis
2.1,安装php
参考 http://blog.csdn.net/jom_ch/article/details/6577156
2.2,安装phpredis扩展
wget https://github.com/nicolasff/phpredis/archive/master.zip
(如果下载的master文件没有扩展名,mv master master.zip)
unzip master.zip
cd phpredis-master
/data/apps/php5.5.0/bin/phpize
./configure --with-php-config=/data/apps/php5.5.0/bin/php-config
make
make install
2.3,编辑php.ini
vim php.ini
在 Dynamic Extensions 后面添加
extension = /data/apps/php5.5.0/lib/php/extensions/no-debug-non-zts-20121212/redis.so
重启php
2.4,测试代码
<?php
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
$redis->set('foo','bar');
echo $redis->get('foo');