Fixed #33826 -- Fixed RedisCache.set_many()/delete_many() crash with an empty list.
This commit is contained in:
parent
fcee0d3fb6
commit
608ab043f7
|
@ -214,6 +214,8 @@ class RedisCache(BaseCache):
|
||||||
return self._cache.incr(key, delta)
|
return self._cache.incr(key, delta)
|
||||||
|
|
||||||
def set_many(self, data, timeout=DEFAULT_TIMEOUT, version=None):
|
def set_many(self, data, timeout=DEFAULT_TIMEOUT, version=None):
|
||||||
|
if not data:
|
||||||
|
return []
|
||||||
safe_data = {}
|
safe_data = {}
|
||||||
for key, value in data.items():
|
for key, value in data.items():
|
||||||
key = self.make_and_validate_key(key, version=version)
|
key = self.make_and_validate_key(key, version=version)
|
||||||
|
@ -222,6 +224,8 @@ class RedisCache(BaseCache):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def delete_many(self, keys, version=None):
|
def delete_many(self, keys, version=None):
|
||||||
|
if not keys:
|
||||||
|
return
|
||||||
safe_keys = [self.make_and_validate_key(key, version=version) for key in keys]
|
safe_keys = [self.make_and_validate_key(key, version=version) for key in keys]
|
||||||
self._cache.delete_many(safe_keys)
|
self._cache.delete_many(safe_keys)
|
||||||
|
|
||||||
|
|
|
@ -577,6 +577,9 @@ class BaseCacheTests:
|
||||||
self.assertIsNone(cache.get("key1"))
|
self.assertIsNone(cache.get("key1"))
|
||||||
self.assertIsNone(cache.get("key2"))
|
self.assertIsNone(cache.get("key2"))
|
||||||
|
|
||||||
|
def test_set_many_empty_data(self):
|
||||||
|
self.assertEqual(cache.set_many({}), [])
|
||||||
|
|
||||||
def test_delete_many(self):
|
def test_delete_many(self):
|
||||||
# Multiple keys can be deleted using delete_many
|
# Multiple keys can be deleted using delete_many
|
||||||
cache.set_many({"key1": "spam", "key2": "eggs", "key3": "ham"})
|
cache.set_many({"key1": "spam", "key2": "eggs", "key3": "ham"})
|
||||||
|
@ -585,6 +588,9 @@ class BaseCacheTests:
|
||||||
self.assertIsNone(cache.get("key2"))
|
self.assertIsNone(cache.get("key2"))
|
||||||
self.assertEqual(cache.get("key3"), "ham")
|
self.assertEqual(cache.get("key3"), "ham")
|
||||||
|
|
||||||
|
def test_delete_many_no_keys(self):
|
||||||
|
self.assertIsNone(cache.delete_many([]))
|
||||||
|
|
||||||
def test_clear(self):
|
def test_clear(self):
|
||||||
# The cache can be emptied using clear
|
# The cache can be emptied using clear
|
||||||
cache.set_many({"key1": "spam", "key2": "eggs"})
|
cache.set_many({"key1": "spam", "key2": "eggs"})
|
||||||
|
|
Loading…
Reference in New Issue