当前最新的稳定版本是3.2.8,以此版本为例
下载
wget http://download.redis.io/releases/redis-3.2.8.tar.gz
tar xvf redis-3.2.8.tar.gz
编译安装
cd redis-3.2.8
make
sudo make install
配置
sudo mkdir /etc/redis
sudo cp redis.conf /etc/redis/6379.conf
sudo vim /etc/redis/6379.conf
修改配置
daemonize yes
开机自启动
sudo cp ./utils/redis_init_script /etc/init.d/redis
sudo vim /etc/init.d/redis
头部注释增加一行
# chkconfig: 2345 10 90
sudo chkconfig redis on
启动并测试
sudo service redis start
redis-cli
>quit
php redis扩展
wget http://pecl.php.net/get/redis-3.1.2.tgz
phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
sudo make install
如果没有安装autconf,请用yum install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/ 修改php.inn
sudo vim /etc/php.ini
[redis]
extension_dir = /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303
extension = redis.so
重启 php-fpm
sudo service php-fpm restart
前面的test.php页面应该能够看到redis扩展被启用。 简单测试代码
<?php
$redis = new Redis();
$redis->connect("127.0.0.1", 6379);
$redis->set("say", "hello");
echo $redis->get("say");
$redis->del("say");
echo $redis->get("say");