Skip to content

Commit e1306c0

Browse files
JD MaturenJD Maturen
authored andcommitted
Add support for LPUSHX, RPUSHX, LINSERT
1 parent 3e04eb2 commit e1306c0

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

redis/client.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class Redis(threading.local):
207207
bool
208208
),
209209
string_keys_to_dict(
210-
'DECRBY HLEN INCRBY LLEN SCARD SDIFFSTORE SINTERSTORE '
210+
'DECRBY HLEN INCRBY LINSERT LLEN LPUSHX RPUSHX SCARD SDIFFSTORE SINTERSTORE '
211211
'SUNIONSTORE ZCARD ZREMRANGEBYRANK ZREMRANGEBYSCORE ZREVRANK',
212212
int
213213
),
@@ -750,7 +750,16 @@ def lindex(self, name, index):
750750
end of the list
751751
"""
752752
return self.execute_command('LINDEX', name, index)
753-
753+
754+
def linsert(self, name, where, refvalue, value):
755+
"""
756+
Insert ``value`` in list ``name`` either immediately before or after [``where``] ``refvalue``
757+
758+
Returns positive int length of the list on success, -1 if ``refvalue`` is not in the list,
759+
0 if ``name`` is not a list.
760+
"""
761+
return self.execute_command('LINSERT', name, where, refvalue, value)
762+
754763
def llen(self, name):
755764
"Return the length of the list ``name``"
756765
return self.execute_command('LLEN', name)
@@ -762,6 +771,10 @@ def lpop(self, name):
762771
def lpush(self, name, value):
763772
"Push ``value`` onto the head of the list ``name``"
764773
return self.execute_command('LPUSH', name, value)
774+
775+
def lpushx(self, name, value):
776+
"Push ``value`` onto the head of the list ``name`` if ``name`` exists"
777+
return self.execute_command('LPUSHX', name, value)
765778

766779
def lrange(self, name, start, end):
767780
"""
@@ -838,6 +851,10 @@ def rpush(self, name, value):
838851
"Push ``value`` onto the tail of the list ``name``"
839852
return self.execute_command('RPUSH', name, value)
840853

854+
def rpushx(self, name, value):
855+
"Push ``value`` onto the tail of the list ``name`` if ``name`` exists"
856+
return self.execute_command('RPUSHX', name, value)
857+
841858
def sort(self, name, start=None, num=None, by=None, get=None,
842859
desc=False, alpha=False, store=None):
843860
"""

0 commit comments

Comments
 (0)