diff options
| author | Andy McCurdy <andy@andymccurdy.com> | 2018-11-14 21:02:22 -0800 |
|---|---|---|
| committer | Andy McCurdy <andy@andymccurdy.com> | 2018-11-14 21:02:22 -0800 |
| commit | b97fc767bee9e108b0b8a856e64649d08074e320 (patch) | |
| tree | 329dbad6aa0551fe275d5e32decad42b5caf6ef1 | |
| parent | b0d7af3482d4aa8feffcaaee81d4d125769f70b7 (diff) | |
| parent | 2e6f05761ef10a19a18cc91ca05253538dcd8445 (diff) | |
| download | redis-py-b97fc767bee9e108b0b8a856e64649d08074e320.tar.gz | |
Merge branch 'master' of github.com:andymccurdy/redis-py
| -rwxr-xr-x | redis/client.py | 2 | ||||
| -rwxr-xr-x | redis/connection.py | 27 |
2 files changed, 18 insertions, 11 deletions
diff --git a/redis/client.py b/redis/client.py index d909823..c2a9070 100755 --- a/redis/client.py +++ b/redis/client.py @@ -589,7 +589,7 @@ class Redis(object): charset=None, errors=None, decode_responses=False, retry_on_timeout=False, ssl=False, ssl_keyfile=None, ssl_certfile=None, - ssl_cert_reqs=None, ssl_ca_certs=None, + ssl_cert_reqs='required', ssl_ca_certs=None, max_connections=None): if not connection_pool: if charset is not None: diff --git a/redis/connection.py b/redis/connection.py index 87beb01..b38f24c 100755 --- a/redis/connection.py +++ b/redis/connection.py @@ -468,6 +468,7 @@ class Connection(object): 'db': self.db, } self._connect_callbacks = [] + self._buffer_cutoff = 6000 def __repr__(self): return self.description_format % self._description_args @@ -654,10 +655,11 @@ class Connection(object): buff = SYM_EMPTY.join((SYM_STAR, str(len(args)).encode(), SYM_CRLF)) + buffer_cutoff = self._buffer_cutoff for arg in imap(self.encoder.encode, args): # to avoid large string mallocs, chunk the command into the # output list if we're sending large values - if len(buff) > 6000 or len(arg) > 6000: + if len(buff) > buffer_cutoff or len(arg) > buffer_cutoff: buff = SYM_EMPTY.join( (buff, SYM_DOLLAR, str(len(arg)).encode(), SYM_CRLF)) output.append(buff) @@ -675,16 +677,21 @@ class Connection(object): output = [] pieces = [] buffer_length = 0 + buffer_cutoff = self._buffer_cutoff for cmd in commands: for chunk in self.pack_command(*cmd): - pieces.append(chunk) - buffer_length += len(chunk) - - if buffer_length > 6000: - output.append(SYM_EMPTY.join(pieces)) - buffer_length = 0 - pieces = [] + chunklen = len(chunk) + if buffer_length > buffer_cutoff or chunklen > buffer_cutoff: + output.append(SYM_EMPTY.join(pieces)) + buffer_length = 0 + pieces = [] + + if chunklen > self._buffer_cutoff: + output.append(chunk) + else: + pieces.append(chunk) + buffer_length += chunklen if pieces: output.append(SYM_EMPTY.join(pieces)) @@ -694,8 +701,8 @@ class Connection(object): class SSLConnection(Connection): description_format = "SSLConnection<host=%(host)s,port=%(port)s,db=%(db)s>" - def __init__(self, ssl_keyfile=None, ssl_certfile=None, ssl_cert_reqs=None, - ssl_ca_certs=None, **kwargs): + def __init__(self, ssl_keyfile=None, ssl_certfile=None, + ssl_cert_reqs='required', ssl_ca_certs=None, **kwargs): if not ssl_available: raise RedisError("Python wasn't built with SSL support") |
