Skip to content

Commit

Permalink
Fix crash: key expire while search (#2270)
Browse files Browse the repository at this point in the history
* fix expire while search

* sleep
  • Loading branch information
dvora-h committed Nov 21, 2022
1 parent a4ff8a6 commit de903f2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion redis/commands/search/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 14 additions & 0 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -1698,3 +1698,17 @@ 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]
time.sleep(1)
assert 2 == modclient.ft().search(Query("*")).total

0 comments on commit de903f2

Please sign in to comment.