第十一节 python和集群交互

 1 # pip installl redis-py-cluster
 2 from rediscluster import StrictRedisCluster
 3 
 4 if __name__ == '__main__':
 5     '''构建所有的住节点,Redis会使用CRC16算法,将键和值写到某个节点上'''
 6     try:
 7         startup_nodes = [
 8             {'host':'ip', 'port':'7000'},
 9             {'host':'ip', 'port':'7001'},
10             {'host':'ip', 'port':'7002'}
11         ]
12         src = StrictRedisCluster(startup_nodes=startup_nodes, decode_responses=True)
13             reselt = src.set('name','itheima')
14             name = src.get('name')
15     except Exception as e:
16         print(e)
posted @ 2020-03-05 14:19  kog_maw  阅读(240)  评论(0编辑  收藏  举报