summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Colish <dcolish@gmail.com>2011-03-14 16:53:57 -0400
committerDan Colish <dcolish@gmail.com>2011-03-14 16:53:57 -0400
commit2f772ba93d887a4c3b6cc5256168c7ab48e89409 (patch)
treec91a8477d5e1b2dd572b5aa25da9f1685af3b254
parent7a9fea265989916d0db910d3d049e085a43044af (diff)
downloadredis-py-2f772ba93d887a4c3b6cc5256168c7ab48e89409.tar.gz
Use itertools izip and islice to speed up pairs_to_dict and other zips
-rw-r--r--redis/client.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/redis/client.py b/redis/client.py
index b091e23..2c7e404 100644
--- a/redis/client.py
+++ b/redis/client.py
@@ -2,7 +2,7 @@ import datetime
import threading
import time
import warnings
-from itertools import chain, imap
+from itertools import chain, imap, islice, izip
from redis.connection import ConnectionPool, Connection
from redis.exceptions import ConnectionError, ResponseError, WatchError
from redis.exceptions import RedisError, AuthenticationError
@@ -75,7 +75,8 @@ def parse_info(response):
def pairs_to_dict(response):
"Create a dict given a list of key/value pairs"
- return dict(zip(response[::2], response[1::2]))
+ return dict(izip(islice(response, None, None, 2),
+ islice(response, 1, None, 2)))
def zset_score_pairs(response, **options):
"""
@@ -84,7 +85,8 @@ def zset_score_pairs(response, **options):
"""
if not response or not options['withscores']:
return response
- return zip(response[::2], map(float, response[1::2]))
+ return list(izip(islice(response, None, None, 2),
+ imap(float, islice(response, 1, None, 2))))
def int_or_none(response):
if response is None:
@@ -1300,7 +1302,7 @@ class Pipeline(Redis):
"pipeline execution")
# Run any callbacks for the commands run in the pipeline
data = []
- for r, cmd in zip(response, commands):
+ for r, cmd in izip(response, commands):
if not isinstance(r, Exception):
if cmd[0] in self.RESPONSE_CALLBACKS:
r = self.RESPONSE_CALLBACKS[cmd[0]](r, **cmd[2])