diff options
author | Chris Dent <chdent@redhat.com> | 2015-03-20 15:50:56 +0000 |
---|---|---|
committer | Julien Danjou <julien@danjou.info> | 2015-03-25 15:01:24 +0100 |
commit | 01859a03e84e7b5de8dc08bbdff0d458e4130c51 (patch) | |
tree | eb716cf55e2401441728745bb918f5d33f0d00e6 | |
parent | 889f86cc15fab48d1f6a82bbb868de44d4f03afa (diff) | |
download | tooz-01859a03e84e7b5de8dc08bbdff0d458e4130c51.tar.gz |
Use a sentinel connection pool to manage failover
When configured to use sentinel with the redis driver, allow the
redis-py client to manage the connection to the currently elected
master.
'master_for' will return a StricRedis client which is bound to a
connection pool that queries the Sentinel[s] when providing
connections from the pool.
This means that failover handling is automatic as long as the
sentinels can be reached and they have elected a new master.
Change-Id: I8fd672e664d98097944a7c984cadab5fb08dd2d6
Closes-Bug: #1434043
(cherry picked from commit 54d6bb1c94270d2794ecefbcaf3f8832010e3d58)
-rw-r--r-- | tooz/drivers/redis.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/tooz/drivers/redis.py b/tooz/drivers/redis.py index f52d36a..6ae7c46 100644 --- a/tooz/drivers/redis.py +++ b/tooz/drivers/redis.py @@ -348,13 +348,14 @@ class RedisDriver(coordination.CoordinationDriver): sentinel_server = sentinel.Sentinel( sentinel_hosts, socket_timeout=kwargs['socket_timeout']) - master_host, master_port = sentinel_server.discover_master( - kwargs['sentinel']) - kwargs['host'] = master_host - kwargs['port'] = master_port + sentinel_name = kwargs['sentinel'] del kwargs['sentinel'] if 'sentinel_fallback' in kwargs: del kwargs['sentinel_fallback'] + master_client = sentinel_server.master_for(sentinel_name, **kwargs) + # The master_client is a redis.StrictRedis using a + # Sentinel managed connection pool. + return master_client return redis.StrictRedis(**kwargs) def _start(self): |