Redis部署文档
一 安装Redis
1.下载redis到服务器
wget http://redis.googlecode.com/files/redis-2.4.2.tar.gz
2.安装
tar –xzvf redis-2.4.2.tar.gz
cd redis-2.4.2
make
make install
3.建立db目录
mkdir -p /data/redis
4. 创建配置文件和日志目录
mkdir -p /usr/local/redis
mkdir /var/log/redis
vi /usr/local/redis/redis.conf
daemonize yes
#是否以后台进程运行,默认为no
pidfile /var/redis.pid
port 6379
timeout 300
loglevel notice
logfile /var/log/redis/redis.log
databases 16
save 60 5000
rdbcompression yes
dbfilename redisdb.rdb
dir /data/redis
#requirepass redis
maxclients 10000
#最大客户端连接数,默认不限制
maxmemory 6GB
#设置最大内存,达到最大内存设置后,Redis会先尝试清除已到期或即将到期的Key,当此方法处理后,任到达最大内存设置,将无法再进行写入操作
5.启动redis
/usr/local/bin/redis-server /usr/local/redis/redis.conf
查看是否正常启动
netstat -anp|grep redis
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 13994/redis-server
ps aux|grep redis
测试
/usr/local/bin/redis-cli set testkey v
/usr/local/bin/redis-cli get testkey
二、安装phpredis扩展
cd nicolasff-phpredis-c991437
shell> /usr/local/php/bin/phpize 这个phpize是安装php模块的
shell> ./configure –with-php-config=/usr/local/php/bin/php-config
shell> make
shell> make install
接下来在php.ini中添加extension=redis.so
重启nginx
Php测试:<?php
$redis = new Redis();
$redis->connect(‘127.0.0.1′,6379);
$redis->set(‘test’,'hello world!’);
echo $redis->get(‘test’);
?>
三:项目部署
各个系统Zend包里面 Zend\Cache\Backend\
Zend\Cache\Frontend 里面分别拷贝进去 redis.php
修改 BabySitter\CacheManager.php 相关Redis配置
使用:
$cacheObj=BabySitter_CacheManager::getInstance()->getCache(‘Test’,30);
$cacheObj->save(‘testKey’,’tom’);
$cacheObj->load(‘testKey’);//tom