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