1 安装redis-py-cluster

pip3 install redis-py-cluster

image.png

2 代码测试

  1. from rediscluster import RedisCluster
  2. if __name__ == '__main__':
  3. nodes = [
  4. {"host": "192.168.3.67", "port": "7000"},
  5. {"host": "192.168.3.67", "port": "7001"},
  6. {"host": "192.168.3.67", "port": "7002"},
  7. ]
  8. rc = RedisCluster(startup_nodes=nodes)
  9. ret = rc.set("age", 17)
  10. print(ret) # True

会随机放到集群中的任一个master, 获取的时候会自动切换
image.png