Skip to content

Commit 40168a6

Browse files
committed
LPUSHX support for list, no API changes
Part of redis#1546
1 parent 879584b commit 40168a6

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Diff for: redis/commands.py

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

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

13121312
def lrange(self, name, start, end):
13131313
"""

Diff for: tests/test_commands.py

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

1266+
@skip_if_server_version_lt('4.0.0')
1267+
def test_lpushx_with_list(self, r):
1268+
# now with a list
1269+
r.lpush('somekey', 'a')
1270+
r.lpush('somekey', 'b')
1271+
assert r.lpushx('somekey', 'foo', 'asdasd', 55, 'asdasdas') == 6
1272+
res = r.lrange('somekey', 0, -1)
1273+
assert res == [b'asdasdas', b'55', b'asdasd', b'foo', b'b', b'a']
1274+
12661275
def test_lrange(self, r):
12671276
r.rpush('a', '1', '2', '3', '4', '5')
12681277
assert r.lrange('a', 0, 2) == [b'1', b'2', b'3']

0 commit comments

Comments
 (0)