summaryrefslogtreecommitdiff
path: root/redis/client.py
diff options
context:
space:
mode:
Diffstat (limited to 'redis/client.py')
-rwxr-xr-xredis/client.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/redis/client.py b/redis/client.py
index fe6299f..160f495 100755
--- a/redis/client.py
+++ b/redis/client.py
@@ -2965,6 +2965,28 @@ class Redis:
}
return self.execute_command('ZPOPMIN', name, *args, **options)
+ def zrandmember(self, key, count=None, withscores=False):
+ """
+ Return a random element from the sorted set value stored at key.
+
+ ``count`` if the argument is positive, return an array of distinct
+ fields. If called with a negative count, the behavior changes and
+ the command is allowed to return the same field multiple times.
+ In this case, the number of returned fields is the absolute value
+ of the specified count.
+
+ ``withscores`` The optional WITHSCORES modifier changes the reply so it
+ includes the respective scores of the randomly selected elements from
+ the sorted set.
+ """
+ params = []
+ if count is not None:
+ params.append(count)
+ if withscores:
+ params.append("WITHSCORES")
+
+ return self.execute_command("ZRANDMEMBER", key, *params)
+
def bzpopmax(self, keys, timeout=0):
"""
ZPOPMAX a value off of the first non-empty sorted set