Fix for crash when sentinel_master_id is absent in config
This commit is contained in:
parent
00e6cace76
commit
6d0ad85d48
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user