You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Exception raised when publishing from a pubsub object #151
import redis
r = redis.Redis(password='yomama')
r.publish('foo','bar')
This code fails, although the message is correctly published before the code raises an exception:
import redis
r = redis.Redis(password='yomama')
ps = r.pubsub()
ps.publish('foo','bar')
Traceback (most recent call last):
File "./test2", line 6, in
ps.publish('foo','bar')
File "/Users/nfarring/.virtualenvs/mordia/lib/python2.7/site-packages/redis/client.py", line 1136, in publish
return self.execute_command('PUBLISH', channel, message)
File "/Users/nfarring/.virtualenvs/mordia/lib/python2.7/site-packages/redis/client.py", line 1063, in execute_command
return self.parse_response()
File "/Users/nfarring/.virtualenvs/mordia/lib/python2.7/site-packages/redis/client.py", line 1078, in parse_response
if response[0] in self.subscribe_commands:
TypeError: 'long' object is not subscriptable
Here is the same output using ipython:
TypeError Traceback (most recent call last)
/Users/nfarring/ in ()
/Users/nfarring/.virtualenvs/mordia/lib/python2.7/site-packages/redis/client.pyc in publish(self, channel, message)
1134 Returns the number of subscribers the message was delivered to.
1135 """
-> 1136 return self.execute_command('PUBLISH', channel, message)
1137
1138 def listen(self):
/Users/nfarring/.virtualenvs/mordia/lib/python2.7/site-packages/redis/client.pyc in parse_response(self)
1076 "Parse the response from a publish/subscribe command"
1077 response = self.connection.read_response()
-> 1078 if response[0] in self.subscribe_commands:
1079 self.subscription_count = response[2]
1080 # if we've just unsubscribed from the remaining channels,
It was an error to add the publish command to the PubSub object. While the error you describe above is a failure on the Python side, Redis actually prevents publishing to any connection that's currently [P]SUBSCRIBEd to one or more channels. Therefore, having publish on PubSub objects isn't very useful. Instead, you should use publish on the base Redis class to send messages.
I've already removed publish from the PubSub class in master which will become 2.4.6 within the next day or two.
Once the client enters the subscribed state it is not supposed to issue any other commands, except for additional SUBSCRIBE, PSUBSCRIBE, UNSUBSCRIBE and PUNSUBSCRIBE commands.
The above commands are allowed by Redis but the Python client doesn't allow any command at all after listen() (the equivalent of entering the 'subscribe state').
@eyison This seems like a completely different issue. I suspect the TCP connection between the client and server was interrupted. I would suggest using one of the keepalive settings.
Activity
andymccurdy commentedon Jul 11, 2011
It was an error to add the
publishcommand to the PubSub object. While the error you describe above is a failure on the Python side, Redis actually prevents publishing to any connection that's currently [P]SUBSCRIBEd to one or more channels. Therefore, havingpublishon PubSub objects isn't very useful. Instead, you should usepublishon the base Redis class to send messages.I've already removed
publishfrom the PubSub class in master which will become 2.4.6 within the next day or two.Thanks for the bug report!
saidimu commentedon Nov 30, 2012
According to the Redis docs on
SUBSCRIBE:The above commands are allowed by Redis but the Python client doesn't allow any command at all after
listen()(the equivalent of entering the 'subscribe state').eyison commentedon Jul 15, 2019
when I listened,after a while,I can‘t get message any more
andymccurdy commentedon Jul 15, 2019
@eyison This seems like a completely different issue. I suspect the TCP connection between the client and server was interrupted. I would suggest using one of the keepalive settings.