summaryrefslogtreecommitdiff
path: root/redis/client.py
diff options
context:
space:
mode:
authorandy <andy@whiskeymedia.com>2012-10-07 21:07:04 -0700
committerandy <andy@whiskeymedia.com>2012-10-07 21:07:04 -0700
commit7661d4199fa4393a1a55a26c09e921ff7dc98dbc (patch)
treebaba08c6087b2440613b4a5d471612027e908c3e /redis/client.py
parente46c78bc14cde3f371ae2b520d206f5f62923d46 (diff)
downloadredis-py-7661d4199fa4393a1a55a26c09e921ff7dc98dbc.tar.gz
Added optional `number` argument to srandmember. Fix for #286
Diffstat (limited to 'redis/client.py')
-rw-r--r--redis/client.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/redis/client.py b/redis/client.py
index 3e84056..104ae85 100644
--- a/redis/client.py
+++ b/redis/client.py
@@ -927,9 +927,16 @@ class StrictRedis(object):
"Remove and return a random member of set ``name``"
return self.execute_command('SPOP', name)
- def srandmember(self, name):
- "Return a random member of set ``name``"
- return self.execute_command('SRANDMEMBER', name)
+ def srandmember(self, name, number=None):
+ """
+ If ``number`` is None, returns a random member of set ``name``.
+
+ If ``number`` is supplied, returns a list of ``number`` random
+ memebers of set ``name``. Note this is only available when running
+ Redis 2.6+.
+ """
+ args = number and [number] or []
+ return self.execute_command('SRANDMEMBER', name, *args)
def srem(self, name, *values):
"Remove ``values`` from set ``name``"