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

Fix set_many to work with empty dict

Instead of raising an exception it should just return without doing anything.
parent f122db04
......@@ -318,6 +318,9 @@ class BaseRedisCache(BaseCache):
raise NotImplementedError
def _set_many(self, client, data):
# Only call mset if there actually is some data to save
if not data:
return True
return client.mset(data)
def set_many(self, data, timeout=DEFAULT_TIMEOUT, version=None):
......
......@@ -345,6 +345,11 @@ class BaseRedisTestCase(SetupMixin):
self.assertEqual(self.cache.get("key1"), "spam")
self.assertEqual(self.cache.get("key2"), "eggs")
def test_set_many_works_with_empty_dict(self):
# This test passes if no exception is raised
self.cache.set_many({})
self.cache.set_many({}, version=2)
def test_set_many_expiration(self):
# set_many takes a second ``timeout`` parameter
self.cache.set_many({"key1": "spam", "key2": "eggs"}, 1)
......
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