summaryrefslogtreecommitdiff
path: root/redis/client.py
diff options
context:
space:
mode:
authorAngusP <a7cp3ar50n@gmail.com>2017-01-24 00:03:38 +0000
committerAngusP <a7cp3ar50n@gmail.com>2017-01-24 00:03:38 +0000
commitc7f75a8822e1eb859deb2f87f1186649099b954b (patch)
treecc365d31bee39a2c01d0ebe4715c207fcbc3f15b /redis/client.py
parentd49aaacb7dd454781fd9cb2cd2cb92e9c07d7d31 (diff)
downloadredis-py-c7f75a8822e1eb859deb2f87f1186649099b954b.tar.gz
Implement PUBSUB * commands
PUBSUB CHANNELS, PUBSUB NUMSUB and PUBSUB NUMPAT are implemented as per https://redis.io/commands/pubsub and suggested in Issue #526. Implemented test class `TestPubSubPubSubSubcommands` to test added commands. Tested against python 3.4.2 and python 2.7.5
Diffstat (limited to 'redis/client.py')
-rwxr-xr-xredis/client.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/redis/client.py b/redis/client.py
index b37e96d..b8dec5b 100755
--- a/redis/client.py
+++ b/redis/client.py
@@ -339,6 +339,10 @@ def parse_georadius_generic(response, **options):
]
+def parse_pubsub_numsub(response, **options):
+ return list(zip(response[0::2], response[1::2]))
+
+
class StrictRedis(object):
"""
Implementation of the Redis protocol.
@@ -447,6 +451,7 @@ class StrictRedis(object):
'GEOHASH': lambda r: list(map(nativestr, r)),
'GEORADIUS': parse_georadius_generic,
'GEORADIUSBYMEMBER': parse_georadius_generic,
+ 'PUBSUB NUMSUB': parse_pubsub_numsub,
}
)
@@ -2012,6 +2017,24 @@ class StrictRedis(object):
"""
return self.execute_command('PUBLISH', channel, message)
+ def pubsub_channels(self):
+ """
+ Return a list of channels
+ """
+ return self.execute_command('PUBSUB CHANNELS')
+
+ def pubsub_numpat(self):
+ """
+ Returns the number of subscriptions to patterns
+ """
+ return self.execute_command('PUBSUB NUMPAT')
+
+ def pubsub_numsub(self, *args):
+ """
+ Return a list of the number of subscribers for each channel given in ``*args``
+ """
+ return self.execute_command('PUBSUB NUMSUB', *args)
+
def cluster(self, cluster_arg, *args):
return self.execute_command('CLUSTER %s' % cluster_arg.upper(), *args)