redis-py Sentinel的使用

Sentinel初始化例子

from redis.sentinel import Sentinel
conf = {
    'sentinel': [('10.160.84.01', 26379), ('10.160.85.02', 26379), ('10.160.86.03', 26379)],
    'master_group_name': 'mymaster',
    #連接sentinel配置
    'sentinel_conf': { 
        'socket_timeout': 3,
        'socket_keepalive': True,
        'password': 'w2opw723DaAp0rUc'
    },
    'connection_conf': {
        'socket_timeout': 3,
        'retry_on_timeout': True,
        'socket_keepalive': True,
        'max_connections': 5,
        'db': 0,
        'password': 'w2opw723DaAp0rUc',
        'encoding': 'utf8'
    }
}
sentinel = Sentinel(conf['sentinel'],sentinel_kwargs=conf['sentinel_conf'],**conf['connection_conf'])
sentinel.discover_master(conf['master_group_name'])
cli = sentinel.master_for(conf['master_group_name'])
cli.set('hello', 'word')
cli.get('hello')

關於哨兵的詳細細節解釋,在下面的鏈接:
https://huangzhw.github.io/2019/03/23/how-redis-py-sentinel-work/#redis-py%E9%87%8C%E7%9A%84sentinel%E5%88%B0%E5%BA%95%E6%98%AF%E5%A6%82%E4%BD%95%E5%B7%A5%E4%BD%9C%E7%9A%84

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章