Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue with SUBSCRIBE and pipes #30

Closed
thomasst opened this issue Apr 17, 2010 · 3 comments
Closed

issue with SUBSCRIBE and pipes #30

thomasst opened this issue Apr 17, 2010 · 3 comments

Comments

@thomasst
Copy link
Contributor

Sample code:

redis = Redis()

# If I enable this line it works (i.e. executing any redis command before executing the pipe). This shouldn't be required though.
#redis.exists('z')

pipe = redis.pipeline()
pipe.subscribe('z')
print 'exec', pipe.execute()

for msg in pipe.listen():
    print msg


Output:

Traceback (most recent call last):
  File "sub.py", line 14, in 
    print 'exec', pipe.execute()
  File "/home/tom/lib/redis/client.py", line 1151, in execute
    return execute(stack)
  File "/home/tom/lib/redis/client.py", line 1113, in _execute_transaction
    self.connection.send(all_cmds, self)
  File "/home/tom/lib/redis/client.py", line 81, in send
    self.connect(redis_instance)
  File "/home/tom/lib/redis/client.py", line 66, in connect
    redis_instance._setup_connection()
  File "/home/tom/lib/redis/client.py", line 395, in _setup_connection
    self.execute_command('SELECT', self.connection.db)
  File "/home/tom/lib/redis/client.py", line 302, in execute_command
    **options
  File "/home/tom/lib/redis/client.py", line 1100, in _execute_command
    command_name, command, **options)
  File "/home/tom/lib/redis/client.py", line 278, in _execute_command
    raise RedisError("Cannot issue commands other than SUBSCRIBE and "
redis.exceptions.RedisError: Cannot issue commands other than SUBSCRIBE and UNSUBSCRIBE while channels are open
@thomasst
Copy link
Contributor Author

Also, the following does not work:

redis.exists('z')

pipe = redis.pipeline()

pipe.zrange('z', 0, -1)
pipe.subscribe('z')

msgs, subs = pipe.execute()
print msgs

redis.unsubscribe()

print 'unsubscribed'

redis.exists('z')

pipe = redis.pipeline()

pipe.zrange('z', 0, -1)
pipe.subscribe('z')

msgs, subs = pipe.execute() # fails here
print msgs

redis.unsubscribe()
Traceback (most recent call last):
  File "sub.py", line 36, in 
    msgs, subs = pipe.execute()
  File "/home/tom/lib/redis/client.py", line 1151, in execute
    return execute(stack)
  File "/home/tom/lib/redis/client.py", line 1120, in _execute_transaction
    raise ResponseError("Wrong number of response items from "
redis.exceptions.ResponseError: Wrong number of response items from pipline execution

BTW: "pipline" has a typo.

@andymccurdy
Copy link
Contributor

So I took another look at this during PyCon. I'm tempted to just make calling (P)SUBSCRIBE, (P)UNSUBSCRIBE and LISTEN impossible from pipelines. Can anyone give me a use case why they'd want to subscribe or listen to channels from a pipeline?

@andymccurdy
Copy link
Contributor

redis-py 2.4 removes the ability for pipelines to subscribe to channels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants