Commit 5945ea9c authored by Sean Bleier's avatar Sean Bleier

Fixed bug with 'get_many' not handling integers correctly.

parent 70877eb9
...@@ -28,6 +28,9 @@ class CacheKey(object): ...@@ -28,6 +28,9 @@ class CacheKey(object):
def __str__(self): def __str__(self):
return self.__unicode__() return self.__unicode__()
def __repr__(self):
return self.__unicode__()
def __unicode__(self): def __unicode__(self):
return smart_str(self._key) return smart_str(self._key)
...@@ -162,6 +165,9 @@ class CacheClass(BaseCache): ...@@ -162,6 +165,9 @@ class CacheClass(BaseCache):
for key, value in zip(new_keys, results): for key, value in zip(new_keys, results):
if value is None: if value is None:
continue continue
try:
value = int(value)
except (ValueError, TypeError):
value = self.unpickle(value) value = self.unpickle(value)
if isinstance(value, basestring): if isinstance(value, basestring):
value = smart_unicode(value) value = smart_unicode(value)
......
...@@ -83,6 +83,20 @@ class RedisCacheTests(TestCase): ...@@ -83,6 +83,20 @@ class RedisCacheTests(TestCase):
self.assertEqual(self.cache.get_many(['a', 'c', 'd']), {'a' : 'a', 'c' : 'c', 'd' : 'd'}) self.assertEqual(self.cache.get_many(['a', 'c', 'd']), {'a' : 'a', 'c' : 'c', 'd' : 'd'})
self.assertEqual(self.cache.get_many(['a', 'b', 'e']), {'a' : 'a', 'b' : 'b'}) self.assertEqual(self.cache.get_many(['a', 'b', 'e']), {'a' : 'a', 'b' : 'b'})
def test_get_many_with_manual_integer_insertion(self):
keys = ['a', 'b', 'c', 'd']
cache_keys = map(self.cache.make_key, keys)
# manually set integers and then get_many
for i, key in enumerate(cache_keys):
self.cache._client.set(key, i)
self.assertEqual(self.cache.get_many(keys), {'a': 0, 'b': 1, 'c': 2, 'd': 3})
def test_get_many_with_automatic_integer_insertion(self):
keys = ['a', 'b', 'c', 'd']
for i, key in enumerate(keys):
self.cache.set(key, i)
self.assertEqual(self.cache.get_many(keys), {'a': 0, 'b': 1, 'c': 2, 'd': 3})
def test_delete(self): def test_delete(self):
# Cache keys can be deleted # Cache keys can be deleted
self.cache.set("key1", "spam") self.cache.set("key1", "spam")
......
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