diff options
author | Andy McCurdy <andy@andymccurdy.com> | 2017-07-31 16:05:01 -0400 |
---|---|---|
committer | Andy McCurdy <andy@andymccurdy.com> | 2017-07-31 16:05:01 -0400 |
commit | 5dced57b6c74b7a7d2342ff705fa239dfa5a2597 (patch) | |
tree | 3d97f3f29eded71dd31a960fc33699af7d644358 | |
parent | a3502de93b5d74b28a1a8952515b5775b14c653f (diff) | |
download | redis-py-5dced57b6c74b7a7d2342ff705fa239dfa5a2597.tar.gz |
added get_encoding() to ConnectionPool
-rwxr-xr-x | redis/client.py | 11 | ||||
-rwxr-xr-x | redis/connection.py | 10 |
2 files changed, 14 insertions, 7 deletions
diff --git a/redis/client.py b/redis/client.py index 4bab5fb..e72c1b1 100755 --- a/redis/client.py +++ b/redis/client.py @@ -2338,13 +2338,10 @@ class PubSub(object): self.connection = None # we need to know the encoding options for this connection in order # to lookup channel and pattern names for callback handlers. - conn = connection_pool.get_connection('pubsub', shard_hint) - try: - self.encoding = conn.encoding - self.encoding_errors = conn.encoding_errors - self.decode_responses = conn.decode_responses - finally: - connection_pool.release(conn) + encoding_options = self.connection_pool.get_encoding() + self.encoding = encoding_options['encoding'] + self.encoding_errors = encoding_options['encoding_errors'] + self.decode_responses = encoding_options['decode_responses'] self.reset() def __del__(self): diff --git a/redis/connection.py b/redis/connection.py index 728a627..77eb44d 100755 --- a/redis/connection.py +++ b/redis/connection.py @@ -394,6 +394,7 @@ class HiredisParser(BaseParser): raise response[0] return response + if HIREDIS_AVAILABLE: DefaultParser = HiredisParser else: @@ -955,6 +956,15 @@ class ConnectionPool(object): self._in_use_connections.add(connection) return connection + def get_encoding(self): + "Return information about the encoding settings" + kwargs = self.connection_kwargs + return { + 'encoding': kwargs.get('encoding', 'utf-8'), + 'encoding_errors': kwargs.get('encoding_errors', 'strict'), + 'decode_responses': kwargs.get('decode_responses', False) + } + def make_connection(self): "Create a new connection" if self._created_connections >= self.max_connections: |