1 安装redis-py-cluster
pip3 install redis-py-cluster
2 代码测试
from rediscluster import RedisCluster
if __name__ == '__main__':
nodes = [
{"host": "192.168.3.67", "port": "7000"},
{"host": "192.168.3.67", "port": "7001"},
{"host": "192.168.3.67", "port": "7002"},
]
rc = RedisCluster(startup_nodes=nodes)
ret = rc.set("age", 17)
print(ret) # True
会随机放到集群中的任一个master, 获取的时候会自动切换