Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions redis/commands/json/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def arrindex(
name: str,
path: str,
scalar: int,
start: Optional[int] = 0,
stop: Optional[int] = -1,
start: Optional[int] = None,
stop: Optional[int] = None,
) -> List[Union[int, None]]:
"""
Return the index of ``scalar`` in the JSON array under ``path`` at key
Expand All @@ -43,9 +43,13 @@ def arrindex(

For more information see `JSON.ARRINDEX <https://redis.io/commands/json.arrindex>`_.
""" # noqa
return self.execute_command(
"JSON.ARRINDEX", name, str(path), self._encode(scalar), start, stop
)
pieces = [name, str(path), self._encode(scalar)]
if start:
pieces.append(start)
if stop:
pieces.append(stop)

return self.execute_command("JSON.ARRINDEX", *pieces)

def arrinsert(
self, name: str, path: str, index: int, *args: List[JsonType]
Expand Down
2 changes: 2 additions & 0 deletions tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ def test_arrindex(client):
client.json().set("arr", Path.root_path(), [0, 1, 2, 3, 4])
assert 1 == client.json().arrindex("arr", Path.root_path(), 1)
assert -1 == client.json().arrindex("arr", Path.root_path(), 1, 2)
assert 4 == client.json().arrindex("arr", Path.root_path(), 4)
# assert -1 == client.json().arrindex("arr", Path.root_path(), 4, start=0, stop=-1)


@pytest.mark.redismod
Expand Down