python redis客户端简单使用

哨兵配置参考:https://blog.csdn.net/baidu_30809315/article/details/108409780 

    pip install redis
def redis_pool_client():
    import redis
    redis_pool = redis.ConnectionPool(host='192.168.0.1', port=6379, password='123456')
    redis_client = redis.Redis(connection_pool=redis_pool)
    redis_client.set('name', 'jalen')
    redis_client.get('name')
def redis_sentinel_client():
    from redis.sentinel import Sentinel
    conf = {
        'sentinel': [('192.168.0.3', 26379), ('192.168.0.4', 26379), ('192.168.0.5', 26379)],
        'master_group_name': 'mymaster',
        'connection_conf': {
            'socket_timeout': 0.5,
            'retry_on_timeout': True,
            'socket_keepalive': True,
            'max_connections': 10,
            'db': 0,
            'encoding': 'utf8',
            'decode_responses': True,
        }
    }
    sentinel = Sentinel(conf['sentinel'], **conf['connection_conf'])
    ip, port = sentinel.discover_master(conf['master_group_name'])
    logger.info('master ip: %s' % ip)
    logger.info('master port: %s' % port)
    sentinel_client = sentinel.master_for(conf['master_group_name'], password='123456')
    sentinel_client.set('name', 'jalen')
    sentinel_client.get('name')

 

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jalen备忘录

谢谢~~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值