StrictRedisCluster是个坑
-
安装包如下
pip install redis-py-cluster
-
-
-
-
-
-
创建⽂件redis_cluster.py,示例码如下
from rediscluster import * if __name__ == '__main__': try: # 构建所有的节点,Redis会使⽤CRC16算法,将键和值写到某个节点上 startup_nodes = [{'host': '192.168.10.129', 'port': '7000'},
{'host': '192.168.10.129', 'port': '7001'},
{'host': '192.168.10.129', 'port': '7002'},
{'host': '192.168.10.129', 'port': '7006'},
{'host': '192.168.10.129', 'port': '7007'},
{'host': '192.168.10.130', 'port': '7003'},
{'host': '192.168.10.130', 'port': '7004'},
{'host': '192.168.10.130', 'port': '7005'}] -
# 构建Cluster对象 -
src=RedisCluster(startup_nodes=startup_nodes,decode_responses=True) #StrictRedisCluster,这个方法是不对的! -
# 设置键为name、值为itheima的数据 -
result=src.set('name','redis') -
print(result) -
# 获取键为 -
name name = src.get('name') -
print(name) -
except Exception as e: -
print(e)
-
-
-
-
-
浙公网安备 33010602011771号