From 01859a03e84e7b5de8dc08bbdff0d458e4130c51 Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Fri, 20 Mar 2015 15:50:56 +0000 Subject: 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) --- tooz/drivers/redis.py | 9 +++++---- 1 file 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): -- cgit v1.2.1