diff options
author | JD Maturen <jdm...@gmail> | 2010-10-07 22:43:45 -0700 |
---|---|---|
committer | JD Maturen <jd@xx.local> | 2010-10-07 22:44:41 -0700 |
commit | e1306c03d4932cf0f6345335e3041e99d8829a82 (patch) | |
tree | b5a79bc5961a8819d23dc329a01613953b8e1c8d | |
parent | 3e04eb29b0655f5bec892ed85b4ea7fb1bdb5869 (diff) | |
download | redis-py-e1306c03d4932cf0f6345335e3041e99d8829a82.tar.gz |
Add support for LPUSHX, RPUSHX, LINSERT
-rw-r--r-- | redis/client.py | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/redis/client.py b/redis/client.py index 8281435..9e9b184 100644 --- a/redis/client.py +++ b/redis/client.py @@ -207,7 +207,7 @@ class Redis(threading.local): bool ), string_keys_to_dict( - 'DECRBY HLEN INCRBY LLEN SCARD SDIFFSTORE SINTERSTORE ' + 'DECRBY HLEN INCRBY LINSERT LLEN LPUSHX RPUSHX SCARD SDIFFSTORE SINTERSTORE ' 'SUNIONSTORE ZCARD ZREMRANGEBYRANK ZREMRANGEBYSCORE ZREVRANK', int ), @@ -750,7 +750,16 @@ class Redis(threading.local): end of the list """ return self.execute_command('LINDEX', name, index) - + + def linsert(self, name, where, refvalue, value): + """ + Insert ``value`` in list ``name`` either immediately before or after [``where``] ``refvalue`` + + Returns positive int length of the list on success, -1 if ``refvalue`` is not in the list, + 0 if ``name`` is not a list. + """ + return self.execute_command('LINSERT', name, where, refvalue, value) + def llen(self, name): "Return the length of the list ``name``" return self.execute_command('LLEN', name) @@ -762,6 +771,10 @@ class Redis(threading.local): def lpush(self, name, value): "Push ``value`` onto the head of the list ``name``" return self.execute_command('LPUSH', name, value) + + def lpushx(self, name, value): + "Push ``value`` onto the head of the list ``name`` if ``name`` exists" + return self.execute_command('LPUSHX', name, value) def lrange(self, name, start, end): """ @@ -838,6 +851,10 @@ class Redis(threading.local): "Push ``value`` onto the tail of the list ``name``" return self.execute_command('RPUSH', name, value) + def rpushx(self, name, value): + "Push ``value`` onto the tail of the list ``name`` if ``name`` exists" + return self.execute_command('RPUSHX', name, value) + def sort(self, name, start=None, num=None, by=None, get=None, desc=False, alpha=False, store=None): """ |