From 364f22abdbdb6208bfee4519510ded3eb81aad8e Mon Sep 17 00:00:00 2001 From: Gabriel Erzse Date: Wed, 5 Jun 2024 15:30:42 +0300 Subject: [PATCH] Fix parsing of INFO response (#3265) If the INFO response contains a single `a=b` value for any of the keys, that must also be parsed into a dictionary. Fixes #3262 Co-authored-by: Gabriel Erzse --- redis/_parsers/helpers.py | 2 +- tests/test_parsers/test_helpers.py | 35 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 tests/test_parsers/test_helpers.py diff --git a/redis/_parsers/helpers.py b/redis/_parsers/helpers.py index aa115aa4a1..57b12ab89e 100644 --- a/redis/_parsers/helpers.py +++ b/redis/_parsers/helpers.py @@ -38,7 +38,7 @@ def parse_info(response): response = str_if_bytes(response) def get_value(value): - if "," not in value or "=" not in value: + if "," not in value and "=" not in value: try: if "." in value: return float(value) diff --git a/tests/test_parsers/test_helpers.py b/tests/test_parsers/test_helpers.py new file mode 100644 index 0000000000..6430a237f6 --- /dev/null +++ b/tests/test_parsers/test_helpers.py @@ -0,0 +1,35 @@ +from redis._parsers.helpers import parse_info + + +def test_parse_info(): + info_output = """ +# Modules +module:name=search,ver=999999,api=1,filters=0,usedby=[],using=[ReJSON],options=[handle-io-errors] + +# search_fields_statistics +search_fields_text:Text=3 +search_fields_tag:Tag=2,Sortable=1 + +# search_version +search_version:99.99.99 +search_redis_version:7.2.2 - oss + +# search_runtime_configurations +search_query_timeout_ms:500 + """ + info = parse_info(info_output) + + assert isinstance(info["modules"], list) + assert isinstance(info["modules"][0], dict) + assert info["modules"][0]["name"] == "search" + + assert isinstance(info["search_fields_text"], dict) + assert info["search_fields_text"]["Text"] == 3 + + assert isinstance(info["search_fields_tag"], dict) + assert info["search_fields_tag"]["Tag"] == 2 + assert info["search_fields_tag"]["Sortable"] == 1 + + assert info["search_version"] == "99.99.99" + assert info["search_redis_version"] == "7.2.2 - oss" + assert info["search_query_timeout_ms"] == 500