Skip to content

Commit de903f2

Browse files
committed
Fix crash: key expire while search (#2270)
* fix expire while search * sleep
1 parent a4ff8a6 commit de903f2

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

redis/commands/search/result.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(
3838
score = float(res[i + 1]) if with_scores else None
3939

4040
fields = {}
41-
if hascontent:
41+
if hascontent and res[i + fields_offset] is not None:
4242
fields = (
4343
dict(
4444
dict(

tests/test_search.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,3 +1698,17 @@ def test_dialect(modclient: redis.Redis):
16981698
with pytest.raises(redis.ResponseError) as err:
16991699
modclient.ft().explain(Query("@title:(@num:[0 10])").dialect(2))
17001700
assert "Syntax error" in str(err)
1701+
1702+
1703+
@pytest.mark.redismod
1704+
def test_expire_while_search(modclient: redis.Redis):
1705+
modclient.ft().create_index((TextField("txt"),))
1706+
modclient.hset("hset:1", "txt", "a")
1707+
modclient.hset("hset:2", "txt", "b")
1708+
modclient.hset("hset:3", "txt", "c")
1709+
assert 3 == modclient.ft().search(Query("*")).total
1710+
modclient.pexpire("hset:2", 300)
1711+
for _ in range(500):
1712+
modclient.ft().search(Query("*")).docs[1]
1713+
time.sleep(1)
1714+
assert 2 == modclient.ft().search(Query("*")).total

0 commit comments

Comments
 (0)