Skip to content

LPUSHX support for list, no API changes #1559

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

Merged
merged 1 commit into from
Sep 1, 2021
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
4 changes: 2 additions & 2 deletions redis/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1305,9 +1305,9 @@ def lpush(self, name, *values):
"Push ``values`` onto the head of the list ``name``"
return self.execute_command('LPUSH', name, *values)

def lpushx(self, name, value):
def lpushx(self, name, *values):
"Push ``value`` onto the head of the list ``name`` if ``name`` exists"
return self.execute_command('LPUSHX', name, value)
return self.execute_command('LPUSHX', name, *values)

def lrange(self, name, start, end):
"""
Expand Down
9 changes: 9 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,15 @@ def test_lpushx(self, r):
assert r.lpushx('a', '4') == 4
assert r.lrange('a', 0, -1) == [b'4', b'1', b'2', b'3']

@skip_if_server_version_lt('4.0.0')
def test_lpushx_with_list(self, r):
# now with a list
r.lpush('somekey', 'a')
r.lpush('somekey', 'b')
assert r.lpushx('somekey', 'foo', 'asdasd', 55, 'asdasdas') == 6
res = r.lrange('somekey', 0, -1)
assert res == [b'asdasdas', b'55', b'asdasd', b'foo', b'b', b'a']

def test_lrange(self, r):
r.rpush('a', '1', '2', '3', '4', '5')
assert r.lrange('a', 0, 2) == [b'1', b'2', b'3']
Expand Down