Skip to content

Commit 05d391e

Browse files
authored
Added redis' decode_responses to be able to choose if to decode responses or not (#6)
1 parent 3273421 commit 05d391e

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

mockredis/client.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def __init__(self,
4242
load_lua_dependencies=True,
4343
blocking_timeout=1000,
4444
blocking_sleep_interval=0.01,
45+
decode_responses=False,
4546
**kwargs):
4647
"""
4748
Initialize as either StrictRedis or Redis.
@@ -61,6 +62,7 @@ def __init__(self,
6162
self.pubsub = defaultdict(list)
6263
# Dictionary from script to sha ''Script''
6364
self.shas = dict()
65+
self.decode_responses = decode_responses
6466

6567
@classmethod
6668
def from_url(cls, url, db=None, **kwargs):
@@ -1543,7 +1545,9 @@ def _encode(self, value):
15431545
else:
15441546
value = value.encode('utf-8', 'strict')
15451547

1546-
return value.decode('utf-8', 'strict')
1548+
if self.decode_responses:
1549+
return value.decode('utf-8', 'strict')
1550+
return value
15471551

15481552
def _log(self, level, msg):
15491553
pass
@@ -1559,7 +1563,8 @@ def mock_redis_client(**kwargs):
15591563
can return a MockRedis object
15601564
instead of a Redis object.
15611565
"""
1562-
return MockRedis()
1566+
return MockRedis(**kwargs)
1567+
15631568

15641569
mock_redis_client.from_url = mock_redis_client
15651570

@@ -1570,6 +1575,7 @@ def mock_strict_redis_client(**kwargs):
15701575
can return a MockRedis object
15711576
instead of a StrictRedis object.
15721577
"""
1573-
return MockRedis(strict=True)
1578+
return MockRedis(strict=True, **kwargs)
1579+
15741580

15751581
mock_strict_redis_client.from_url = mock_strict_redis_client

0 commit comments

Comments
 (0)