summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChayim <chayim@users.noreply.github.com>2021-09-01 13:10:56 +0300
committerGitHub <noreply@github.com>2021-09-01 13:10:56 +0300
commite53227cf68c065b4d31f39cdde7c85c5e91dd1bf (patch)
tree39d0455c889091895a51e4554de7195c10b6db8d
parent3dc2bf906f634383d33952d36cd78156a6e36e0e (diff)
downloadredis-py-e53227cf68c065b4d31f39cdde7c85c5e91dd1bf.tar.gz
LPUSHX support for list, no API changes (#1559)
Part of #1546
-rw-r--r--redis/commands.py4
-rw-r--r--tests/test_commands.py9
2 files changed, 11 insertions, 2 deletions
diff --git a/redis/commands.py b/redis/commands.py
index 895b00a..6e816de 100644
--- a/redis/commands.py
+++ b/redis/commands.py
@@ -1318,9 +1318,9 @@ class Commands:
"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):
"""
diff --git a/tests/test_commands.py b/tests/test_commands.py
index 6877265..1698106 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -1271,6 +1271,15 @@ class TestRedisCommands:
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']