Skip to content

Commit 85dafcc

Browse files
authored
More robust parsing of memory stats response (#3247)
Make the parsing of memory stats response more robust, to not break on changes that will be added to the Redis server. Also make a test related to client kill by maxage more resilient. Co-authored-by: Gabriel Erzse <[email protected]>
1 parent b7a85eb commit 85dafcc

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

redis/_parsers/helpers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def parse_memory_stats(response, **kwargs):
8080
"""Parse the results of MEMORY STATS"""
8181
stats = pairs_to_dict(response, decode_keys=True, decode_string_values=True)
8282
for key, value in stats.items():
83-
if key.startswith("db."):
83+
if key.startswith("db.") and isinstance(value, list):
8484
stats[key] = pairs_to_dict(
8585
value, decode_keys=True, decode_string_values=True
8686
)

tests/test_asyncio/test_commands.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3235,7 +3235,7 @@ async def test_memory_stats(self, r: redis.Redis):
32353235
assert isinstance(stats, dict)
32363236
for key, value in stats.items():
32373237
if key.startswith("db."):
3238-
assert isinstance(value, dict)
3238+
assert not isinstance(value, list)
32393239

32403240
@skip_if_server_version_lt("4.0.0")
32413241
async def test_memory_usage(self, r: redis.Redis):

tests/test_commands.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ def test_client_kill_filter_by_user(self, r, request):
712712
def test_client_kill_filter_by_maxage(self, r, request):
713713
_get_client(redis.Redis, request, flushdb=False)
714714
time.sleep(4)
715-
assert len(r.client_list()) == 2
715+
assert len(r.client_list()) >= 2
716716
r.client_kill_filter(maxage=2)
717717
assert len(r.client_list()) == 1
718718

@@ -4914,7 +4914,7 @@ def test_memory_stats(self, r):
49144914
assert isinstance(stats, dict)
49154915
for key, value in stats.items():
49164916
if key.startswith("db."):
4917-
assert isinstance(value, dict)
4917+
assert not isinstance(value, list)
49184918

49194919
@skip_if_server_version_lt("4.0.0")
49204920
def test_memory_usage(self, r):

0 commit comments

Comments
 (0)