diff options
author | Nick Pope <nick.pope@flightdataservices.com> | 2020-08-17 23:04:31 +0100 |
---|---|---|
committer | Nick Pope <nick.pope@flightdataservices.com> | 2020-08-17 23:35:23 +0100 |
commit | a2ae894af65ee74ac13947092d980d98b9b5005f (patch) | |
tree | 53975d4d49d60fa7a429cd61fb6925eded6d827f /pymemcache | |
parent | 6605f850753b1c5569910c7fb5570e547341350f (diff) | |
download | pymemcache-a2ae894af65ee74ac13947092d980d98b9b5005f.tar.gz |
Used collections.defaultdict() in HashClient.{get,set}_many().
Diffstat (limited to 'pymemcache')
-rw-r--r-- | pymemcache/client/hash.py | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/pymemcache/client/hash.py b/pymemcache/client/hash.py index 355400d..83460be 100644 --- a/pymemcache/client/hash.py +++ b/pymemcache/client/hash.py @@ -1,3 +1,4 @@ +import collections import socket import time import logging @@ -339,7 +340,7 @@ class HashClient(object): return self._run_cmd('decr', key, False, *args, **kwargs) def set_many(self, values, *args, **kwargs): - client_batches = {} + client_batches = collections.defaultdict(dict) failed = [] for key, value in six.iteritems(values): @@ -349,9 +350,6 @@ class HashClient(object): failed.append(key) continue - if client.server not in client_batches: - client_batches[client.server] = {} - client_batches[client.server][key] = value for server, values in client_batches.items(): @@ -366,7 +364,7 @@ class HashClient(object): set_multi = set_many def get_many(self, keys, gets=False, *args, **kwargs): - client_batches = {} + client_batches = collections.defaultdict(list) end = {} for key in keys: @@ -376,9 +374,6 @@ class HashClient(object): end[key] = False continue - if client.server not in client_batches: - client_batches[client.server] = [] - client_batches[client.server].append(key) for server, keys in client_batches.items(): |