How can I use Tornado and Redis asynchronously?

后端 未结 4 695
天涯浪人
天涯浪人 2021-02-04 07:31

I\'m trying to find how can I use Redis and Tornado asynchronously. I found the tornado-redis but I need more than just add a yield in the code.

I have the

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-04 08:00

    You should not use Redis pub/sub in the main Tornado thread, as it will block the IO loop. You can handle the long polling from web clients in the main thread, but you should create a separate thread for listening to Redis. You can then use ioloop.add_callback() and/or a threading.Queue to communicate with the main thread when you receive messages.

提交回复
热议问题