diff options
author | Andy McCurdy <andy@andymccurdy.com> | 2018-11-13 11:58:01 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-13 11:58:01 -0800 |
commit | e69ecbb16a207616e4b7cf5ebdd3075d4eb43e61 (patch) | |
tree | 1b61d72599723331f5c836b1c7208a6b82664593 /redis/client.py | |
parent | 3e3c96ffdbf44d6daba841b8b77f6dba4ec02e8a (diff) | |
parent | 4147b2088801040298cc5f595c9ede226e283634 (diff) | |
download | redis-py-e69ecbb16a207616e4b7cf5ebdd3075d4eb43e61.tar.gz |
Merge pull request #1019 from krishan-carbon/patch-1
Allow pings in PubSub
Diffstat (limited to 'redis/client.py')
-rwxr-xr-x | redis/client.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/redis/client.py b/redis/client.py index c6a8e4b..b132336 100755 --- a/redis/client.py +++ b/redis/client.py @@ -3054,6 +3054,13 @@ class PubSub(object): return self.handle_message(response, ignore_subscribe_messages) return None + def ping(self, message=None): + """ + Ping the Redis server + """ + message = '' if message is None else message + return self.execute_command('PING', message) + def handle_message(self, response, ignore_subscribe_messages=False): """ Parses a pub/sub message. If the channel or pattern was subscribed to @@ -3068,6 +3075,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, @@ -3098,7 +3112,7 @@ class PubSub(object): if handler: handler(message) return None - else: + elif message_type != 'pong': # this is a subscribe/unsubscribe message. ignore if we don't # want them if ignore_subscribe_messages or self.ignore_subscribe_messages: |