Skip to content

Commit

Permalink
better error handling whith bad auth passwords
Browse files Browse the repository at this point in the history
  • Loading branch information
thefab committed Oct 15, 2015
1 parent 91bb191 commit 5bc08c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
13 changes: 7 additions & 6 deletions examples/context_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
@tornado.gen.coroutine
def ping_redis(num):
with (yield pool.connected_client()) as client:
# client is a connected tornadis.Client instance
# it will be automatically released to the pool thanks to the
# "with" keyword
reply = yield client.call("PING")
if not isinstance(reply, tornadis.TornadisException):
print("reply #%i : %s" % (num, reply))
if not isinstance(client, tornadis.TornadisException):
# client is a connected tornadis.Client instance
# it will be automatically released to the pool thanks to the
# "with" keyword
reply = yield client.call("PING")
if not isinstance(reply, tornadis.TornadisException):
print("reply #%i : %s" % (num, reply))


@tornado.gen.coroutine
Expand Down
7 changes: 6 additions & 1 deletion tornadis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ def connect(self):
raise tornado.gen.Return(True)
else:
# incorrect password, return back the result
raise tornado.gen.Return(authentication_status)
LOG.warning("impossible to connect: bad password")
self.__connection.disconnect()
raise tornado.gen.Return(False)

def disconnect(self):
"""Disconnects the client object from redis.
Expand Down Expand Up @@ -227,6 +229,9 @@ def async_call(self, *args, **kwargs):
def after_autoconnect_callback(future):
if self.is_connected():
self._call(*args, **kwargs)
else:
# FIXME
pass

if 'callback' not in kwargs:
kwargs['callback'] = discard_reply_cb
Expand Down
5 changes: 4 additions & 1 deletion tornadis/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def get_connected_client(self):
object is available.
Returns:
A Future object with connected Client instance as a result.
A Future object with connected Client instance as a result
(or ClientError if there was a connection problem)
"""
if self.__sem is not None:
yield self.__sem.acquire()
Expand All @@ -85,6 +86,8 @@ def get_connected_client(self):
res = yield client.connect()
if not(res):
LOG.warning("can't connect to %s", client.title)
raise tornado.gen.Return(ClientError("can't connect to %s" %
client.title))
raise tornado.gen.Return(client)

def get_client_nowait(self):
Expand Down

0 comments on commit 5bc08c0

Please sign in to comment.