Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redis-py with gevent

Can redis-py library be used with gevent ?

Does anyone have experience running redis-py library with gevent? Is there a working example?

Do they play nice together? Are there any precautions or hacks to get them to work at scale?

The question in another words:

to make redis-py connections use gevent greenlets , do I have to do anything special other than monkeypatch sockets?

from gevent import monkey

monkey.patch_all()

then use redis-py as usual?

like image 368
Joseph Avatar asked Jun 07 '12 08:06

Joseph


1 Answers

Yes, redis-py works fine with gevent.

You can check my answer to the following question: you will find an example and some remarks.

redis + gevent - Poor performance - what am I doing wrong?

The main trap is to consider that because gevent is asynchronous and the sockets are monkeypatched, the cost of roundtrips to Redis will magically disappear. This is plain wrong.

gevent is mainly interesting when several connections at the same time are used, so that the event loop system calls can be factorized. If the user code generates a lot of synchronous roundtrips to Redis on a small number of connections, it will involve latency, even if these connections are managed in an asynchronous way by gevent.

So even with gevent, pipelining must always be used to optimize the cost of communication.

like image 77
Didier Spezia Avatar answered Nov 05 '22 15:11

Didier Spezia