搭建redis集群
http://www.cnblogs.com/wuxl360/p/5920330.html
http://blog.5ibc.net/p/51020.html
需要安装的东西
redis.io/download">redis-3.0.7
ruby-1.8.7:sudo apt-get install ruby
rubygems:sudo apt-get install rubygems
sudo gem install redis
pip install redis-py-cluster
修改配置文件redis.conf
这里创建3个节点,所以复制3份redis.conf
分别命名为:redis-6379.conf, redis-6380.conf, redis-6381.conf
分别修改其中如下地方,拿redis-6379.conf来举例
port 6379
cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-node-timeout 15000
开启3个redis-server节点
./redis-server ./redis-6379.conf
./redis-server ./redis-6380.conf
./redis-server ./redis-6381.conf
创建redis的集群
./redis-trib.rb create 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381
redis-py-cluster测试客户端
官网:https://github.com/Grokzen/redis-py-cluster
from rediscluster import StrictRedisCluster
startup_nodes = [{"host": "127.0.0.1", "port": "6379"},
{"host": "127.0.0.1", "port": "6380"},
{"host": "127.0.0.1", "port": "6381"}
]
# Note: decode_responses must be set to True when used with Python3
rc = StrictRedisCluster(startup_nodes=startup_nodes, decode_responses=True)
rc.set("foo", "bar")
print rc.get("foo")
著作权归作者所有。
商业转载请联系作者获得授权,非商业转载请注明出处。
作者:吾爱编程
链接:http://blog.5ibc.net