diff options
-rw-r--r-- | redis/client.py | 18 | ||||
-rw-r--r-- | tests/server_commands.py | 4 |
2 files changed, 17 insertions, 5 deletions
diff --git a/redis/client.py b/redis/client.py index c560507..6405947 100644 --- a/redis/client.py +++ b/redis/client.py @@ -242,7 +242,9 @@ class Redis(threading.local): ) # commands that should NOT pull data off the network buffer when executed - SUBSCRIPTION_COMMANDS = set(['SUBSCRIBE', 'UNSUBSCRIBE', 'PSUBSCRIBE', 'PUNSUBSCRIBE']) + SUBSCRIPTION_COMMANDS = set([ + 'SUBSCRIBE', 'UNSUBSCRIBE', 'PSUBSCRIBE', 'PUNSUBSCRIBE' + ]) def __init__(self, host='localhost', port=6379, db=0, password=None, socket_timeout=None, @@ -1193,9 +1195,17 @@ class Redis(threading.local): "Listen for messages on channels this client has been subscribed to" while self.subscribed: r = self.parse_response('LISTEN') - message_type, channel, message = r[0], r[1], r[2] - yield (message_type, channel, message) - if message_type == 'unsubscribe' and message == 0: + if r[0] == 'pmessage': + msg = { + 'type': r[0], + 'pattern': r[1], + 'channel': r[2], + 'data': r[3] + } + else: + msg = {'type': r[0], 'channel': r[1], 'data': r[2]} + yield msg + if r[0] == 'unsubscribe' and r[2] == 0: self.subscribed = False diff --git a/tests/server_commands.py b/tests/server_commands.py index 0a2acf1..b6ae82b 100644 --- a/tests/server_commands.py +++ b/tests/server_commands.py @@ -1072,7 +1072,9 @@ class ServerCommandsTestCase(unittest.TestCase): if len(messages) == num_messages_to_expect: break sent_types, sent_channels = {}, {} - for msg_type, channel, _ in messages: + for msg in messages: + msg_type = msg['type'] + channel = msg['channel'] sent_types.setdefault(msg_type, 0) sent_types[msg_type] += 1 if msg_type == 'message': |