一、安装Redis(各版本下载地址 http://download.redis.io/releases/)
wget -P /soft http://download.redis.io/releases/redis-stable.tar.gz
cd /soft
tar xzf redis-stable.tar.gz
cd redis-stable/
把redis安装到指定目录
make PREFIX=/usr/local/redis install
把配置文件拷贝到指定目录
cp redis.conf /usr/local/bin/redis
编辑配置文件
vim /usr/local/redis/bin/redis.conf
把 daemonize no 改成 daemonize yes ,这样redis就在后台启动
启动redis
/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
测试
[root@VM_129_241_centos src]# /usr/local/redis/bin/redis-cli get name
(nil)
[root@VM_129_241_centos src]# /usr/local/redis/bin/redis-cli set name landy
OK
[root@VM_129_241_centos src]# /usr/local/redis/bin/redis-cli get name
"landy"
二、安装php的Redis扩展(安装包下载地址http://pecl.php.net/package/redis)
wget -P /soft http://pecl.php.net/get/redis-3.1.3.tgz
cd /soft
tar zxvf redis-3.1.3.tgz
cd redis-3.1.3
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
成功安装后,在文件夹中会生成扩展
/usr/local/php/lib/php/extensions/no-debug-zts-20160303/ redis.so
配置php.ini文件
三、php使用Redis
<?php //连接本地的 Redis 服务 $redis = new Redis(); $redis->connect('127.0.0.1', 6379); echo "Connection to server sucessfully"; //设置 redis 字符串数据 $redis->set("tutorial-name", "Redis tutorial"); // 获取存储的数据并输出 echo "Stored string in redis:: " . $redis->get("tutorial-name");