From c9afca807b4fb9a9e93fe382539885ef6668fbba Mon Sep 17 00:00:00 2001 From: David Fuentes Baldomir Date: Thu, 6 Sep 2018 15:34:16 +0200 Subject: [PATCH 1/3] Pass connection options through CACHEOPS_SENTINEL fixes #286 This changes make possible to define socket timeouts both for Sentinel and Redis connections, as well as any other extra configuration accepted by the connection pool. --- cacheops/redis.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cacheops/redis.py b/cacheops/redis.py index 7262085e..cea5d291 100644 --- a/cacheops/redis.py +++ b/cacheops/redis.py @@ -93,12 +93,14 @@ def redis_client(): if not {'locations', 'service_name'} <= set(settings.CACHEOPS_SENTINEL): raise ImproperlyConfigured("Specify locations and service_name for CACHEOPS_SENTINEL") - sentinel = Sentinel(settings.CACHEOPS_SENTINEL['locations']) + sentinel = Sentinel(settings.CACHEOPS_SENTINEL['locations'], **{ + k: v for k, v in settings.CACHEOPS_SENTINEL.items() + if k not in ('locations', 'service_name', 'db') + }) return sentinel.master_for( settings.CACHEOPS_SENTINEL['service_name'], redis_class=client_class, - db=settings.CACHEOPS_SENTINEL.get('db', 0), - socket_timeout=settings.CACHEOPS_SENTINEL.get('socket_timeout') + db=settings.CACHEOPS_SENTINEL.get('db', 0) ) # Allow client connection settings to be specified by a URL. From b7da7fa9db1a43a6d3125f97b8d12b9447e6505e Mon Sep 17 00:00:00 2001 From: David Fuentes Date: Mon, 17 Sep 2018 17:13:41 +0200 Subject: [PATCH 2/3] Use funcy.omit() to build Sentinel configuration --- cacheops/redis.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cacheops/redis.py b/cacheops/redis.py index cea5d291..b5a0a100 100644 --- a/cacheops/redis.py +++ b/cacheops/redis.py @@ -6,7 +6,7 @@ from django.core.exceptions import ImproperlyConfigured from django.utils.module_loading import import_string -from funcy import decorator, identity, memoize, LazyObject +from funcy import decorator, identity, memoize, omit, LazyObject import redis from redis.sentinel import Sentinel from .conf import settings @@ -93,10 +93,9 @@ def redis_client(): if not {'locations', 'service_name'} <= set(settings.CACHEOPS_SENTINEL): raise ImproperlyConfigured("Specify locations and service_name for CACHEOPS_SENTINEL") - sentinel = Sentinel(settings.CACHEOPS_SENTINEL['locations'], **{ - k: v for k, v in settings.CACHEOPS_SENTINEL.items() - if k not in ('locations', 'service_name', 'db') - }) + sentinel = Sentinel( + settings.CACHEOPS_SENTINEL['locations'], + omit(settings.CACHEOPS_SENTINEL, ('locations', 'service_name', 'db'))) return sentinel.master_for( settings.CACHEOPS_SENTINEL['service_name'], redis_class=client_class, From 37eeb874d16c2727c6fea0563786cde3dcf756e8 Mon Sep 17 00:00:00 2001 From: David Fuentes Date: Mon, 17 Sep 2018 17:39:03 +0200 Subject: [PATCH 3/3] Use funcy.omit() to build Sentinel configuration --- cacheops/redis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cacheops/redis.py b/cacheops/redis.py index b5a0a100..ebb2d01f 100644 --- a/cacheops/redis.py +++ b/cacheops/redis.py @@ -95,7 +95,7 @@ def redis_client(): sentinel = Sentinel( settings.CACHEOPS_SENTINEL['locations'], - omit(settings.CACHEOPS_SENTINEL, ('locations', 'service_name', 'db'))) + **omit(settings.CACHEOPS_SENTINEL, ('locations', 'service_name', 'db'))) return sentinel.master_for( settings.CACHEOPS_SENTINEL['service_name'], redis_class=client_class,