diff options
Diffstat (limited to 'redis/connection.py')
-rw-r--r-- | redis/connection.py | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/redis/connection.py b/redis/connection.py index 128c359..b0383f5 100644 --- a/redis/connection.py +++ b/redis/connection.py @@ -124,15 +124,7 @@ class Connection(object): try: sock = self._connect() except socket.error, e: - # args for socket.error can either be (errno, "message") - # or just "message" - if len(e.args) == 1: - error_message = "Error connecting to %s:%s. %s." % \ - (self.host, self.port, e.args[0]) - else: - error_message = "Error %s connecting %s:%s. %s." % \ - (e.args[0], self.host, self.port, e.args[1]) - raise ConnectionError(error_message) + raise ConnectionError(self._error_mesage(e)) self._sock = sock self.on_connect() @@ -144,6 +136,17 @@ class Connection(object): sock.connect((self.host, self.port)) return sock + def _error_message(self, exception): + # args for socket.error can either be (errno, "message") + # or just "message" + if len(exception.args) == 1: + return "Error connecting to %s:%s. %s." % \ + (self.host, self.port, exception.args[0]) + else: + return "Error %s connecting %s:%s. %s." % \ + (exception.args[0], self.host, self.port, exception.args[1]) + + def on_connect(self): "Initialize the connection, authenticate and select a database" self._parser.on_connect(self) @@ -241,6 +244,17 @@ class UnixDomainSocketConnection(Connection): sock.connect(self.path) return sock + def _error_message(self, exception): + # args for socket.error can either be (errno, "message") + # or just "message" + if len(exception.args) == 1: + return "Error connecting to unix socket: %s. %s." % \ + (self.path, exception.args[0]) + else: + return "Error %s connecting to unix socket: %s. %s." % \ + (exception.args[0], self.path, exception.args[1]) + + # TODO: add ability to block waiting on a connection to be released class ConnectionPool(object): "Generic connection pool" |