所需依赖
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来举例
1 port 6379 2 cluster-enabled yes 3 cluster-config-file nodes-6379.conf 4 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
1 from rediscluster import StrictRedisCluster 2 3 startup_nodes = [{"host": "127.0.0.1", "port": "6379"}, 4 {"host": "127.0.0.1", "port": "6380"}, 5 {"host": "127.0.0.1", "port": "6381"} 6 ] 7 8 # Note: decode_responses must be set to True when used with Python3 9 rc = StrictRedisCluster(startup_nodes=startup_nodes, decode_responses=True) 10 11 rc.set("foo", "bar") 12 13 print rc.get("foo")