Skip to content

Commit 186cc1a

Browse files
authored
Merge pull request #68 from launchdarkly/drichelson/ch773/python-redisfeaturestore-should-return-default
Fix redis feature store so it returns default when redis is unavailable.
2 parents 6e51add + 037a7a0 commit 186cc1a

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

ldclient/redis_feature_store.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ def init(self, features):
4444

4545
def all(self, callback):
4646
r = redis.Redis(connection_pool=self._pool)
47-
all_features = r.hgetall(self._features_key)
47+
try:
48+
all_features = r.hgetall(self._features_key)
49+
except BaseException as e:
50+
log.error("RedisFeatureStore: Could not retrieve all flags from Redis with error: "
51+
+ e.message + " Returning None")
52+
return callback(None)
53+
4854
if all_features is None or all_features is "":
4955
log.warn("RedisFeatureStore: call to get all flags returned no results. Returning None.")
5056
return callback(None)
@@ -66,8 +72,14 @@ def get(self, key, callback=lambda x: x):
6672
return callback(None)
6773
return callback(f)
6874

69-
r = redis.Redis(connection_pool=self._pool)
70-
f_json = r.hget(self._features_key, key)
75+
try:
76+
r = redis.Redis(connection_pool=self._pool)
77+
f_json = r.hget(self._features_key, key)
78+
except BaseException as e:
79+
log.error("RedisFeatureStore: Could not retrieve flag from redis with error: " + e.message
80+
+ ". Returning None for key: " + key)
81+
return callback(None)
82+
7183
if f_json is None or f_json is "":
7284
log.warn("RedisFeatureStore: feature flag with key: " + key + " not found in Redis. Returning None.")
7385
return callback(None)

0 commit comments

Comments
 (0)