leporo / tornado-redis

Asynchronous Redis client that works within Tornado IO loop.
667 stars 163 forks source link

Client abstracting connection away from connection #82

Closed jonesetc closed 7 years ago

jonesetc commented 9 years ago

I'm currently trying to implement connection retrying for the client right now. I'm doing this by subclassing the Client class and adding a wrapper around Client.connect() to retry some amount of times.

It works well for me because I always try to connect manually before I attempt any commands, but there are many places where the Client checks the connection and instead of using Client.connect() it directly just uses Client.connection.connect().

https://github.com/leporo/tornado-redis/blob/master/tornadoredis/client.py#L1305-1306

if not self.connection.connected():
    self.connection.connect()

The same goes for many disconnects.

https://github.com/leporo/tornado-redis/blob/master/tornadoredis/client.py#L1317-L1320

except Exception as e:
    self.command_stack = []
    self.connection.disconnect()
    raise e

I see no reason for this, and changing all of these to use the methods on Client instead of Client.connection would make adding in reconnects and retries much easier. I will happily submit a pull request, but I just wanted to make sure that there was no reason for the current way before I did.

Thanks