欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

python redis集群_Python3 redis集群连接 (带密码验证)

发布时间:2025/4/17 python 45 豆豆
生活随笔 收集整理的这篇文章主要介绍了 python redis集群_Python3 redis集群连接 (带密码验证) 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

环境:

python 3.7.4

redis集群 单集群(无slave)

很多文章都说redis密码,今天验证的了很多次失败,查了相关资料有才知道连接方式,一下为代码,修改123456为自己代码就可以使用了

from rediscluster import StrictRedisCluster

list = [

'02200000001',

'02200000002',

'02200000003',

'02200000004',

'02200000005',

'02200000006',

'02200000007',

'02200000008',

'02200000009',

'02200000010'

]

def redis_cluster():

redis_nodes = [

{'host':'192.168.0.56','port':7001},

{'host':'192.168.0.56','port':7002},

{'host':'192.168.0.56','port':7003},

]

# print(redis_nodes[1])

try:

redisconn = StrictRedisCluster(startup_nodes=redis_nodes,password='123456')

print(redisconn)

# redisconn.set('yyy','tttt')

# A=redisconn.set('yyy')

# print(A)

except:

print('error')

for i in range(0,len(list)):

redisconn.set('user_phone_'+list[i],'111111')

print(redisconn.get('user_phone_'+list[i]))

redis_cluster()

总结

以上是生活随笔为你收集整理的python redis集群_Python3 redis集群连接 (带密码验证)的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。