Skip to content

Commit

Permalink
added get_encoding() to ConnectionPool
Browse files Browse the repository at this point in the history
  • Loading branch information
andymccurdy committed Jul 31, 2017
1 parent a3502de commit 5dced57
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
11 changes: 4 additions & 7 deletions redis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2338,13 +2338,10 @@ def __init__(self, connection_pool, shard_hint=None,
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):
Expand Down
10 changes: 10 additions & 0 deletions redis/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ def read_response(self):
raise response[0]
return response


if HIREDIS_AVAILABLE:
DefaultParser = HiredisParser
else:
Expand Down Expand Up @@ -955,6 +956,15 @@ def get_connection(self, command_name, *keys, **options):
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:
Expand Down

0 comments on commit 5dced57

Please sign in to comment.