Comments (5)
Actually, I'm not really sure. We should implement auto-reconnect and raise NotConnected in this case. From the tulip mailing list, I understood that it should be the transport that implements the reconnect, and that the transport should call connection_lost
or connection_made
.
Ideas on how to implement such a transport are very welcome.
from asyncio-redis.
I implemented timeout with decorator, added in Connection.getattr (but it is for each call of redis command - not very efficient)
def timeout_aware(self, cmd, protocol, timeout=0.1):
@asyncio.coroutine
@functools.wraps(cmd)
def wrapper(*args, **kwargs):
task = cmd(*args, **kwargs)
result = None
try:
for _ in asyncio.as_completed([task], timeout=timeout):
result = yield from _
except asyncio.futures.TimeoutError:
self.disconnect(protocol) # self is Connection instance
raise
return result
return wrapper
in aiohttp.client package there is even simplier timeout realization:
yield from asyncio.wait_for(
resp.start(proto, wrapper), timeout, loop=loop)
Without a timeout I had a sad situation: after shutting down redis-server, all redis calls are blocked for more than 2 minutes (actually, they had not finished at all).
I'm not sure about implementing timeouts at transport level. With a timeout to each socket operation, you will not be able to listen redis pub/sub (it is long-term operation), and transport can't distinguish GET and BLPOP (which has it's own read timeout at server side).
Reconnects are for protocol too: for pub-sub mode client should resend 'subscribe' commands after reopening socket connections.
I think, for redis timeouts should be at protocol level rather than transport level. Simpliest way for protocol is to became "timeouted" after a timeout, and Connection pool will be able to filter out and reconnect this protocol if necessary.
from asyncio-redis.
Thanks, but I'm not sure yet about this approach.
I'm almost convinced that timeouts should be implemented in the transport, not in the protocol. TCP has a retransmission timeout, but when it's unable to deliver a packet after several retries, it should be the transport, that notifies the protocol that the connection died. On the other hand, if the protocol expects an answer, but the transport doesn't receive anything, the transport is probably unaware of any problems, so in that case it could be the protocol, notifying the transport.
Anyway, I'm not sure, and just asked on the tulip mailing list.
from asyncio-redis.
Hi again!
As I see, a NotConnected exception is now raised after server shut down :)
I wrote a reconnecting connection pool with only RedisProtocol method wrapping and some helper functions to remove failed transport-protocol pair from pool (and do the reconnect)
https://gist.github.com/tumb1er/8024500
Glad if it will help you :)
from asyncio-redis.
Thank you tumb1er, that's nice. I made a little different approach, but it seems to work now. However, I'm still trying to improve everything.
from asyncio-redis.
Related Issues (20)
- ZRangeReply do not have aslist method
- Using context managers HOT 1
- How to release connection from subscribe HOT 1
- Broken on python 3.7.0 HOT 4
- The right way to share the returned connection.
- Unable to turn off auto_reconnect
- Deprecation warning for formatargspec in Python3.7 HOT 1
- Function `asyncio_redis.Connection.create()` hangs if connection can't be established HOT 2
- Python 3.8 DeprecationWarnings; drop support for legacy Python HOT 3
- Future and roadmap of asyncio-redis HOT 5
- Difference between aioredis?
- Release new version? HOT 4
- Update documentation HOT 1
- SPOP [count] argument.
- intersphinx looks for implementation modules
- asyncio_redis should wait for server restart
- Adding python types HOT 1
- Missing ignore_subscribe_messages equivalent HOT 1
- Proposing a PR to fix a few small typos
- Async Class Constructors HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from asyncio-redis.