diff options
author | Krishan Patel <krishan.patel@carbonnv.com> | 2018-08-13 17:27:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-13 17:27:56 +0100 |
commit | f95b27ee1b74952317280f751c59c0ff32d2ffea (patch) | |
tree | 8b2a3a67debdb0cb2252e745d3a44b3c3d9f5efa | |
parent | 413e802f8fe390738bc1e89716083586e0269fd0 (diff) | |
download | redis-py-f95b27ee1b74952317280f751c59c0ff32d2ffea.tar.gz |
Allow pings in PubSub
According to https://redis.io/topics/pubsub, “The commands that are allowed in the context of a subscribed client are SUBSCRIBE, PSUBSCRIBE, UNSUBSCRIBE, PUNSUBSCRIBE, PING and QUIT.”
According to https://redis.io/commands/ping, “If the client is subscribed to a channel or a pattern, it will instead return a multi-bulk with a "pong" in the first position and an empty bulk in the second position, unless an argument is provided in which case it returns a copy of the argument.”
-rwxr-xr-x | redis/client.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/redis/client.py b/redis/client.py index 79e94d0..db68378 100755 --- a/redis/client.py +++ b/redis/client.py @@ -2517,6 +2517,12 @@ class PubSub(object): return self.handle_message(response, ignore_subscribe_messages) return None + def ping(self): + """ + Ping the Redis server + """ + return self.execute_command('PING') + def handle_message(self, response, ignore_subscribe_messages=False): """ Parses a pub/sub message. If the channel or pattern was subscribed to @@ -2531,6 +2537,13 @@ class PubSub(object): 'channel': response[2], 'data': response[3] } + elif message_type == 'pong': + message = { + 'type': message_type, + 'pattern': None, + 'channel': None, + 'data': response[1] + } else: message = { 'type': message_type, |