安装
pip install redis
pip install redis-py-cluster
查看是否安装成功
pip list
直接上代码
(注意,最新版本要用RedisCluster,而不是StrictRedisCluster!!!)
# -*- coding: utf-8 -*-
from rediscluster import RedisCluster
redis_basis_conn = [{'host': '10.69.53.27', 'port': 7001}, {'host': '10.69.53.27', 'port': 7002}, {'host': '10.69.53.28', 'port': 7001}, {'host': '10.69.53.28', 'port': 7002}, {'host': '10.69.53.29', 'port': 7001}, {'host': '10.69.53.29', 'port': 7002}]
res = RedisCluster(startup_nodes=redis_basis_conn, decode_responses=True)
print(res)
结果