diff options
author | root <root@beast-01.local> | 2013-07-03 19:59:39 +0000 |
---|---|---|
committer | root <root@beast-01.local> | 2013-07-03 19:59:39 +0000 |
commit | 16fadbc928d6dd3eaa00b9e63a0ec027d4f1f823 (patch) | |
tree | 8cf7fc1855b4785d5e84c35c815801d06cdcf795 /redis/connection.py | |
parent | 80baa99d2ac8fb5ac3100e5b17e1b2013e407fb7 (diff) | |
download | redis-py-16fadbc928d6dd3eaa00b9e63a0ec027d4f1f823.tar.gz |
Use io.BytesIO in Redis.pack_command -- makes it a little bit faster
Diffstat (limited to 'redis/connection.py')
-rw-r--r-- | redis/connection.py | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/redis/connection.py b/redis/connection.py index 1018843..01638f5 100644 --- a/redis/connection.py +++ b/redis/connection.py @@ -2,6 +2,7 @@ from itertools import chain import os import socket import sys +import io from redis._compat import (b, xrange, imap, byte_to_chr, unicode, bytes, long, BytesIO, nativestr, basestring, @@ -328,14 +329,17 @@ class Connection(object): def pack_command(self, *args): "Pack a series of arguments into a value Redis command" - output = SYM_STAR + b(str(len(args))) + SYM_CRLF + output = io.BytesIO() + output.write(SYM_STAR) + output.write(b(str(len(args)))) + output.write(SYM_CRLF) for enc_value in imap(self.encode, args): - output += SYM_DOLLAR - output += b(str(len(enc_value))) - output += SYM_CRLF - output += enc_value - output += SYM_CRLF - return output + output.write(SYM_DOLLAR) + output.write(b(str(len(enc_value)))) + output.write(SYM_CRLF) + output.write(enc_value) + output.write(SYM_CRLF) + return output.getvalue() class UnixDomainSocketConnection(Connection): |