How to create redis python client from sentinel and use sentinelConnectPool?

48 Views Asked by At

I have sentinel address and master name, so how can I connect using redis-py?

I wish use master_for function with sentinelConnectPool to connect redis and exec command.

Can anyone please give me a relevant example?

I would like to have an example like this:

(but I wish use master_for function with sentinelConnectPool to connect redis and exec command)

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': 'test',
    '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'])
sentinel.discover_master(conf['master_group_name'])
cli = sentinel.master_for(conf['master_group_name'])
cli.set('hello', 'word')
cli.get('hello')
0

There are 0 best solutions below