Skip to content

Commit

Permalink
More robust parsing of memory stats response (#3247)
Browse files Browse the repository at this point in the history
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 <gabriel.erzse@redis.com>
  • Loading branch information
2 people authored and vladvildanov committed Sep 27, 2024
1 parent 60e88cf commit 0cd52d1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion redis/_parsers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def parse_memory_stats(response, **kwargs):
"""Parse the results of MEMORY STATS"""
stats = pairs_to_dict(response, decode_keys=True, decode_string_values=True)
for key, value in stats.items():
if key.startswith("db."):
if key.startswith("db.") and isinstance(value, list):
stats[key] = pairs_to_dict(
value, decode_keys=True, decode_string_values=True
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_asyncio/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3235,7 +3235,7 @@ async def test_memory_stats(self, r: redis.Redis):
assert isinstance(stats, dict)
for key, value in stats.items():
if key.startswith("db."):
assert isinstance(value, dict)
assert not isinstance(value, list)

@skip_if_server_version_lt("4.0.0")
async def test_memory_usage(self, r: redis.Redis):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ def test_client_kill_filter_by_user(self, r, request):
def test_client_kill_filter_by_maxage(self, r, request):
_get_client(redis.Redis, request, flushdb=False)
time.sleep(4)
assert len(r.client_list()) == 2
assert len(r.client_list()) >= 2
r.client_kill_filter(maxage=2)
assert len(r.client_list()) == 1

Expand Down Expand Up @@ -4914,7 +4914,7 @@ def test_memory_stats(self, r):
assert isinstance(stats, dict)
for key, value in stats.items():
if key.startswith("db."):
assert isinstance(value, dict)
assert not isinstance(value, list)

@skip_if_server_version_lt("4.0.0")
def test_memory_usage(self, r):
Expand Down

0 comments on commit 0cd52d1

Please sign in to comment.