From f1f88c8bc7391b3330559405e544975bb24cf1b5 Mon Sep 17 00:00:00 2001 From: dvora-h Date: Mon, 4 Jul 2022 16:49:14 +0300 Subject: [PATCH 1/2] fix expire while search --- redis/commands/search/result.py | 2 +- tests/test_search.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/redis/commands/search/result.py b/redis/commands/search/result.py index 5f4aca6411..451bf89bb7 100644 --- a/redis/commands/search/result.py +++ b/redis/commands/search/result.py @@ -38,7 +38,7 @@ def __init__( score = float(res[i + 1]) if with_scores else None fields = {} - if hascontent: + if hascontent and res[i + fields_offset] is not None: fields = ( dict( dict( diff --git a/tests/test_search.py b/tests/test_search.py index f0a1190fcb..2b1f5bc72b 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -1698,3 +1698,16 @@ def test_dialect(modclient: redis.Redis): with pytest.raises(redis.ResponseError) as err: modclient.ft().explain(Query("@title:(@num:[0 10])").dialect(2)) assert "Syntax error" in str(err) + + +@pytest.mark.redismod +def test_expire_while_search(modclient: redis.Redis): + modclient.ft().create_index((TextField("txt"),)) + modclient.hset("hset:1", "txt", "a") + modclient.hset("hset:2", "txt", "b") + modclient.hset("hset:3", "txt", "c") + assert 3 == modclient.ft().search(Query("*")).total + modclient.pexpire("hset:2", 300) + for _ in range(500): + modclient.ft().search(Query("*")).docs[1] + assert 2 == modclient.ft().search(Query("*")).total From 40703e20c2f168b6c34e4522657002e8cc668566 Mon Sep 17 00:00:00 2001 From: dvora-h Date: Mon, 11 Jul 2022 10:54:45 +0300 Subject: [PATCH 2/2] sleep --- tests/test_search.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_search.py b/tests/test_search.py index 2b1f5bc72b..642418ecdf 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -1710,4 +1710,5 @@ def test_expire_while_search(modclient: redis.Redis): modclient.pexpire("hset:2", 300) for _ in range(500): modclient.ft().search(Query("*")).docs[1] + time.sleep(1) assert 2 == modclient.ft().search(Query("*")).total