首页 > 编程语言 > 详细

python 连接 redis cluster 集群二种方法

时间:2020-03-24 17:45:11      阅读:711      评论:0      收藏:0      [点我收藏+]

安装第三方集群库

pip install redis-py-cluster

第一种方法

python连接redis cluster集群

from rediscluster import StrictRedisCluster

startup_nodes = [
    {"host":"192.168.3.25", "port":6379},  # 主
    {"host":"192.168.3.25", "port":7001},  # 6379的从数据库
    {"host":"192.168.3.25", "port":6380},  # 主
    {"host":"192.168.3.25", "port":7002},  # 6380的从数据库
    {"host":"192.168.3.25", "port":6381},  # 主
    {"host":"192.168.3.25", "port":7003}   # 6381的从数据库
]
redis_store= StrictRedisCluster(startup_nodes=startup_nodes, decode_responses=True)
redis_store.set(‘name‘, ‘老鹰‘)
redis_store.set(‘money‘, ‘10亿‘)
print("My name is: ", redis_store.get(‘name‘))
print "I have money: ", redis_store.get(‘money‘)

第二种方法

startup_nodes = [{"host": "raaabbbccc.redis.rds.aliyuncs.com", "port": 6379}]
redis_store = StrictRedisCluster(startup_nodes=startup_nodes, password="你的redis密码", decode_responses=True, max_connections=200)

python 连接 redis cluster 集群二种方法

原文:https://www.cnblogs.com/gqv2009/p/12559682.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!