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()
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值