Commit 05ba3ff6 authored by Sean Bleier's avatar Sean Bleier

Merge pull request #106 from triposo/master

Use default timeout in set_many.
parents 93ebff72 7c65c1a7
from collections import defaultdict from collections import defaultdict
from redis_cache.backends.base import BaseRedisCache from redis_cache.backends.base import BaseRedisCache
from redis_cache.compat import DEFAULT_TIMEOUT
from redis_cache.sharder import HashRing from redis_cache.sharder import HashRing
...@@ -71,7 +72,7 @@ class ShardedRedisCache(BaseRedisCache): ...@@ -71,7 +72,7 @@ class ShardedRedisCache(BaseRedisCache):
) )
return data return data
def set_many(self, data, timeout=None, version=None): def set_many(self, data, timeout=DEFAULT_TIMEOUT, version=None):
""" """
Set a bunch of values in the cache at once from a dict of key/value Set a bunch of values in the cache at once from a dict of key/value
pairs. This is much more efficient than calling set() multiple times. pairs. This is much more efficient than calling set() multiple times.
...@@ -79,6 +80,8 @@ class ShardedRedisCache(BaseRedisCache): ...@@ -79,6 +80,8 @@ class ShardedRedisCache(BaseRedisCache):
If timeout is given, that timeout will be used for the key; otherwise If timeout is given, that timeout will be used for the key; otherwise
the default cache timeout will be used. the default cache timeout will be used.
""" """
timeout = self.get_timeout(timeout)
clients = self.shard(data.keys(), write=True, version=version) clients = self.shard(data.keys(), write=True, version=version)
if timeout is None: if timeout is None:
......
from redis_cache.compat import DEFAULT_TIMEOUT
try: try:
import cPickle as pickle import cPickle as pickle
except ImportError: except ImportError:
...@@ -52,7 +54,7 @@ class RedisCache(BaseRedisCache): ...@@ -52,7 +54,7 @@ class RedisCache(BaseRedisCache):
versioned_keys = self.make_keys(keys, version=version) versioned_keys = self.make_keys(keys, version=version)
return self._get_many(self.master_client, keys, versioned_keys=versioned_keys) return self._get_many(self.master_client, keys, versioned_keys=versioned_keys)
def set_many(self, data, timeout=None, version=None): def set_many(self, data, timeout=DEFAULT_TIMEOUT, version=None):
""" """
Set a bunch of values in the cache at once from a dict of key/value Set a bunch of values in the cache at once from a dict of key/value
pairs. This is much more efficient than calling set() multiple times. pairs. This is much more efficient than calling set() multiple times.
...@@ -60,6 +62,8 @@ class RedisCache(BaseRedisCache): ...@@ -60,6 +62,8 @@ class RedisCache(BaseRedisCache):
If timeout is given, that timeout will be used for the key; otherwise If timeout is given, that timeout will be used for the key; otherwise
the default cache timeout will be used. the default cache timeout will be used.
""" """
timeout = self.get_timeout(timeout)
versioned_keys = self.make_keys(data.keys(), version=version) versioned_keys = self.make_keys(data.keys(), version=version)
if timeout is None: if timeout is None:
new_data = {} new_data = {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment