下载软件包
wget https://codeload.github.com/phpredis/phpredis/zip/develop
mv develop phpredis.zip
解压unzip phpredis.zip进入解压目录
cd phpredis-develop
执行命令
/usr/local/php/bin/phpize
初始化编译环境./configure --with-php-config=/usr/local/php/bin/php-config
编译安装
make && make install修改php配置文件
vim /usr/local/php/php.ini
// 增加一行extension = redis.so/usr/local/php/bin/php -m |grep redis 检查是否成功
php
redis中文文档 http://www.cnblogs.com/weafer/archive/2011/09/21/2184059.html
Redis实现session共享
php.ini中加入
session.save_handler = "redis"
session.save_path = "tcp://127.0.0.1:6379"
或者apache虚拟主机加入
php_value session.save_handler " redis"
php_value session.save_path " tcp://127.0.0.1:6379"
或者php-fpm.conf对应的pool中加入
php_value[session.save_handler] = redis
php_value[session.save_path] = " tcp://127.0.0.1:6379 "
Redis存储session测试
wget http://ip/.mem_se.txtmv .mem_se.txt /usr/local/apache2/htdocs/session.php
curl localhost/session.php
输出类似于 1443710814<br><br>1443710814<br><br>9jm6nom9ogojedj3pth0iscv22
连接redis:
/usr/local/redis/bin/redis-cli
127.0.0.1:6379> keys //可以把所有的key都列出来
"PHPREDIS_SESSION:9jm6nom9ogojedj3pth0iscv22"
127.0.0.1:6379> get PHPREDIS_SESSION:9jm6nom9ogojedj3pth0iscv22
"TEST|i:1443710814;TEST3|i:1443710814;"