python初学者用redis搭建服务器集群练习的相关点

需要安装的东西
  • redis-3.0.7
  • ruby-1.8.7:sudo apt-get install ruby
  • rubygems:sudo apt-get install rubygems
  • sudo gem install redis
  • # 其中我们如果执行时发现如下问题,请执行上述部分中gem install redis操作
redis-trib.rb:1573: warning: key "threshold" is duplicated and overwritten on line 1573
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- redis (LoadError)
from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from ./redis-trib.rb:25:in `
'
  • 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")


ps 这是以前收集的一篇文章,转自哪里忘记了,请原作者看到时候或其他人知道的时候说声谢谢,并抱歉

你可能感兴趣的:(python初学者用redis搭建服务器集群练习的相关点)