redis安装

安装过程

最新稳定版,Redis 2.0.4 stable

wget http://redis.googlecode.com/files/redis-2.0.4.tar.gz

tar zxf redis-2.0.4.tar.gz

cd redis-2.0.4

与其它软件不同的是,不需要configure。

make

装完了。

 

创建一个目录

mkdir /usr/local/redis2

cp redis-server redis-benchmark redis-cli redis.conf   /usr/local/redis2

 

启动:

./redis-server > /dev/null &

 

测试:

    存值:

./redis-cli set hx value

取值:

./redis-cli get hx

 

安装phpredis模块

 

https://github.com/owlient/phpredis

 

下载phpredis

解压

shell> cd phpredis

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 先要看看有没有extension_dir=/…….

重启apache或者nginx

 

php代码测试

$redis = new Redis();

$redis->connect(‘127.0.0.1′,6379);

$redis->set(‘test’,'hello world!’);

echo $redis->get(‘test’);

?>

   输出hello world!

   http://code.google.com/p/php-redis/

 

Redis主从配置

REDIS主从配置相当简单,一些文章啰里罗嗦的写了一大篇,其实就两句话:

打开从机的redis.conf

 Port 6381 (注:不能跟主机的一样)

 Sleverof 10.0.0.149 6383 (注:ip为主机IP,6383为主机REDIS端口号)

先重启主机,再重启从机

运行./redis-server redis.conf

原文地址:https://www.cnblogs.com/killallspree/p/4053247.html