Skip to content

Commit

Permalink
Support timeout = 0 in search query (#2934)
Browse files Browse the repository at this point in the history
* Support query timeout = 0

In RediSearch query timeout = 0 means unlimited timeout.
In the current implementation, the query timeout is only updated `if timeout` which in case of 0, translates to false.
Since the default timeout of the `query` class is None, replacing the condition with `if self._timeout is not None` will also work for 0.
If the parameter is not a positive integer, redis server will raise an exception.

related issue: #2928 #2839

* added a test to quety.timeout(0)

* raise an exception if query TIMEOUT is a non negative integer

* fixed the query test to catach AttributeError

* Moved validating timeout to timeout()

Raise the exception when the timeout is set instead of when the query is performed

* updates test to catch the exception when query.timeout() is called

* Update redis/commands/search/query.py

Co-authored-by: GuyAv46 <47632673+GuyAv46@users.noreply.github.com>

* Revert "Update redis/commands/search/query.py"

This reverts commit fb2b710.

* Revert "updates test to catch the exception when query.timeout() is called"

This reverts commit 6590130.

* Revert "Moved validating timeout to timeout()"

This reverts commit 7a020bd.

* Revert "fixed the query test to catach AttributeError"

This reverts commit 25d4ddf.

* Revert "raise an exception if query TIMEOUT is a non negative integer"

This reverts commit 3fb2c68.

---------

Co-authored-by: GuyAv46 <47632673+GuyAv46@users.noreply.github.com>
  • Loading branch information
meiravgri and GuyAv46 committed Sep 14, 2023
1 parent 1596ac6 commit 46b736e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion redis/commands/search/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def _get_args_tags(self):
args += self._ids
if self._slop >= 0:
args += ["SLOP", self._slop]
if self._timeout:
if self._timeout is not None:
args += ["TIMEOUT", self._timeout]
if self._in_order:
args.append("INORDER")
Expand Down
2 changes: 2 additions & 0 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2264,6 +2264,8 @@ def test_withsuffixtrie(client: redis.Redis):
def test_query_timeout(r: redis.Redis):
q1 = Query("foo").timeout(5000)
assert q1.get_args() == ["foo", "TIMEOUT", 5000, "LIMIT", 0, 10]
q1 = Query("foo").timeout(0)
assert q1.get_args() == ["foo", "TIMEOUT", 0, "LIMIT", 0, 10]
q2 = Query("foo").timeout("not_a_number")
with pytest.raises(redis.ResponseError):
r.ft().search(q2)

0 comments on commit 46b736e

Please sign in to comment.