redis-py asynchronous pubsub

214 views
Skip to first unread message

mrtn

unread,
Jun 13, 2015, 4:42:34 AM6/13/15
to redi...@googlegroups.com

From redis-py's documentation: 

"Behind the scenes, get_message() uses the system's 'select' module to quickly poll the connection's socket. If there's data available to be read, get_message() will read it, format the message and return it or pass it to a message handler. If there's no data to be read, get_message() will immediately return None. This makes it trivial to integrate into an existing event loop inside your application."

And it gives an example:

while True:
    message
= p.get_message()
   
if message:
       
# do something with the message
    time
.sleep(0.001) # be nice to the system :)

In the context of Tornado (which has a main IOLoop thread), how do I utilize get_message() so that redis-py's subscriber operates in an asynchronous fashion? Do I need to register a periodic callback on Tornado's IOLoop such that get_message() polls the connection periodically?

Josiah Carlson

unread,
Jun 15, 2015, 2:48:53 PM6/15/15
to redi...@googlegroups.com
There are clients for Redis that integrate directly into the Tornadio IO loop. That may work better for dealing with pubsub. Here are a couple:

Some Tornado Redis clients:

 - Josiah


--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at http://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages