Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash: key expire while search #2270

Merged
merged 2 commits into from
Jul 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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