Commit f122db04 authored by Joona Pääkkönen's avatar Joona Pääkkönen

Fix get_many to work with an empty array

Instead of raising an exception it should return an empty dict

This is the same behaviour that the default Django cache backends have.
parent 37c8ec5a
......@@ -302,12 +302,14 @@ class BaseRedisCache(BaseCache):
recovered_data = {}
map_keys = dict(zip(versioned_keys, original_keys))
results = client.mget(versioned_keys)
for key, value in zip(versioned_keys, results):
if value is None:
continue
recovered_data[map_keys[key]] = self.get_value(value)
# Only try to mget if we actually received any keys to get
if map_keys:
results = client.mget(versioned_keys)
for key, value in zip(versioned_keys, results):
if value is None:
continue
recovered_data[map_keys[key]] = self.get_value(value)
return recovered_data
......
......@@ -176,6 +176,9 @@ class BaseRedisTestCase(SetupMixin):
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'})
def test_get_many_works_with_empty_keys_array(self):
self.assertEqual(self.cache.get_many([]), {})
def test_get_many_with_manual_integer_insertion(self):
keys = ['a', 'b', 'c', 'd']
for i, key in enumerate(keys):
......
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