diff --git a/server/lib/python/cartodb_services/cartodb_services/refactor/storage/redis_connection_config.py b/server/lib/python/cartodb_services/cartodb_services/refactor/storage/redis_connection_config.py index 97eb25c..7766539 100644 --- a/server/lib/python/cartodb_services/cartodb_services/refactor/storage/redis_connection_config.py +++ b/server/lib/python/cartodb_services/cartodb_services/refactor/storage/redis_connection_config.py @@ -55,9 +55,9 @@ class RedisConnectionConfigBuilder(object): host = conf['redis_host'] port = conf['redis_port'] - timeout = conf['timeout'] or self.DEFAULT_TIMEOUT - db = conf['redis_db'] or self.DEFAULT_USER_DB - sentinel_id = conf['sentinel_master_id'] + timeout = conf.get('timeout', self.DEFAULT_TIMEOUT) or self.DEFAULT_TIMEOUT + db = conf.get('redis_db', self.DEFAULT_USER_DB) or self.DEFAULT_USER_DB + sentinel_id = conf.get('sentinel_master_id', None) return RedisConnectionConfig(host, port, timeout, db, sentinel_id) diff --git a/server/lib/python/cartodb_services/test/refactor/storage/test_redis_connection_config.py b/server/lib/python/cartodb_services/test/refactor/storage/test_redis_connection_config.py index 9106cdc..90d9895 100644 --- a/server/lib/python/cartodb_services/test/refactor/storage/test_redis_connection_config.py +++ b/server/lib/python/cartodb_services/test/refactor/storage/test_redis_connection_config.py @@ -99,3 +99,17 @@ class TestRedisMetricsConnectionConfigBuilder(TestCase): assert config.timeout == 0.2 assert config.db == 3 assert config.sentinel_id == 'some_master_id' + + def test_it_sets_absent_values_to_none_or_defaults(self): + server_config_storage = InMemoryConfigStorage({ + 'redis_metrics_config': { + 'redis_host': 'myhost.com', + 'redis_port': 6379, + } + }) + config = RedisMetricsConnectionConfigBuilder(server_config_storage).get() + assert config.host == 'myhost.com' + assert config.port == 6379 + assert config.timeout == 1.5 + assert config.db == 5 + assert config.sentinel_id is None