diff options
| author | Andy McCurdy <andy@andymccurdy.com> | 2011-03-15 11:21:46 -0700 |
|---|---|---|
| committer | Andy McCurdy <andy@andymccurdy.com> | 2011-03-15 11:21:46 -0700 |
| commit | 52098ce02c926115c937c1731ac029c269289c7b (patch) | |
| tree | a92eb4e19973d08dfeef2da0d3f6931c2830c56e | |
| parent | 13850b1b9ed34ee69b37a665b526ddea18860025 (diff) | |
| download | redis-py-52098ce02c926115c937c1731ac029c269289c7b.tar.gz | |
Some speed optimizations. Thanks Suor.
| -rw-r--r-- | redis/client.py | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/redis/client.py b/redis/client.py index b634292..cc649db 100644 --- a/redis/client.py +++ b/redis/client.py @@ -48,7 +48,7 @@ def timestamp_to_datetime(response): return datetime.datetime.fromtimestamp(response) def string_keys_to_dict(key_string, callback): - return dict([(key, callback) for key in key_string.split()]) + return dict.fromkeys(key_string.split(), callback) def dict_merge(*dicts): merged = {} @@ -83,8 +83,8 @@ def parse_info(response): def pairs_to_dict(response): "Create a dict given a list of key/value pairs" - return dict(izip(islice(response, None, None, 2), - islice(response, 1, None, 2))) + it = iter(response) + return dict(izip(it, it)) def zset_score_pairs(response, **options): """ @@ -1091,9 +1091,7 @@ class Redis(threading.local): def _zaggregate(self, command, dest, keys, aggregate=None): pieces = [command, dest, len(keys)] if isinstance(keys, dict): - items = keys.items() - keys = [i[0] for i in items] - weights = [i[1] for i in items] + keys, weights = keys.keys(), keys.values() else: weights = None pieces.extend(keys) @@ -1153,9 +1151,9 @@ class Redis(threading.local): Sets each key in the ``mapping`` dict to its corresponding value in the hash ``name`` """ - items = [] - if len(mapping) == 0: + if not mapping: raise DataError("'hmset' with 'mapping' of length 0") + items = [] for pair in mapping.iteritems(): items.extend(pair) return self.execute_command('HMSET', name, *items) |
