Skip to content

Commit e53227c

Browse files
authored
LPUSHX support for list, no API changes (#1559)
Part of #1546
1 parent 3dc2bf9 commit e53227c

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

redis/commands.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1318,9 +1318,9 @@ def lpush(self, name, *values):
13181318
"Push ``values`` onto the head of the list ``name``"
13191319
return self.execute_command('LPUSH', name, *values)
13201320

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

13251325
def lrange(self, name, start, end):
13261326
"""

tests/test_commands.py

+9
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,15 @@ def test_lpushx(self, r):
12711271
assert r.lpushx('a', '4') == 4
12721272
assert r.lrange('a', 0, -1) == [b'4', b'1', b'2', b'3']
12731273

1274+
@skip_if_server_version_lt('4.0.0')
1275+
def test_lpushx_with_list(self, r):
1276+
# now with a list
1277+
r.lpush('somekey', 'a')
1278+
r.lpush('somekey', 'b')
1279+
assert r.lpushx('somekey', 'foo', 'asdasd', 55, 'asdasdas') == 6
1280+
res = r.lrange('somekey', 0, -1)
1281+
assert res == [b'asdasdas', b'55', b'asdasd', b'foo', b'b', b'a']
1282+
12741283
def test_lrange(self, r):
12751284
r.rpush('a', '1', '2', '3', '4', '5')
12761285
assert r.lrange('a', 0, 2) == [b'1', b'2', b'3']

0 commit comments

Comments
 (0)