Redis的安装
cd /usr/local
wget http://download.redis.io/redis-stable.tar.gz
tar zxvf redis-stable.tar.gz
cd redis-stable //进入解压目录
make //编译安装
make install //将可执行程序赋值到/usr/local/bin目录中,当执行程序中就不要输入完整的路径
make test //测试redis是否编译正确
现在,Redis PHP安装完成!
设置Redis PHP驱动程序
从github库下载phpredis
http://github.com/nicolasff/phpredis
当下载它之后,
git checkout 4.1.1
切换到最新版本
cd phpredis
sudo phpize
sudo ./configure
sudo make
sudo make install
如果出现error:
error: Cannot find php-config. Please use --with-php-config=PATH
加上php-config的路径
# sudo ./configure --with-php-config=/usr/local/php/bin/php-config
现在,将“modules
”文件夹的内容复制并粘贴到PHP扩展目录中,并在php.ini
中添加以下行。
extension = redis.so
现在,Redis PHP安装完成!
重启 php-fpm
开启redis服务
进入 src 目录
运行 ./redis-server &
& 表示后台启动
/redis-cli
进入客户端
使用连接到Redis服务器
<?php
//Connecting to Redis server on localhost
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
echo "Connection to server sucessfully";
//check whether server is running or not
echo "Server is running: ".$redis->ping();
?>
当程序执行时,将产生以下结果。
Connection to server sucessfully
Server is running: PONG
教程手册
phpredis 中文手册 : http://www.cnblogs.com/zcy_soft/archive/2012/09/21/2697006.html
手册: http://www.cnblogs.com/weafer/archive/2011/09/21/2184059.html