summaryrefslogtreecommitdiff
path: root/redis/client.py
diff options
context:
space:
mode:
authorAndy McCurdy <andy@andymccurdy.com>2010-06-22 10:04:38 -0700
committerAndy McCurdy <andy@andymccurdy.com>2010-06-22 10:04:38 -0700
commitfb0a249f4a39268e089825a15184d3d1b7ddac62 (patch)
tree79239bb869db6a951d70fd7dc70cb33189db5363 /redis/client.py
parent91441933d3333528f2749a888e2c5db6106493fc (diff)
downloadredis-py-fb0a249f4a39268e089825a15184d3d1b7ddac62.tar.gz
changed return type of listen() -- it's now a dictionary with the following keys: type -- the message type, data -- the actual message, channel -- the channel the message was delivered on. if the message was triggered due to a pattern matched from psubscribe, then a 4th key will be present: pattern, indicating the pattern that was matched.
Diffstat (limited to 'redis/client.py')
-rw-r--r--redis/client.py18
1 files changed, 14 insertions, 4 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