diff --git a/cache/stores/redis/lib.php b/cache/stores/redis/lib.php index e2853d5d01b..2b81e8eaf41 100644 --- a/cache/stores/redis/lib.php +++ b/cache/stores/redis/lib.php @@ -469,7 +469,7 @@ class cachestore_redis extends cache_store implements cache_is_key_aware, cache_ $ttlparams[] = $key; } } - if ($usettl) { + if ($usettl && count($ttlparams) > 0) { // Store all the key values with current time. $this->redis->zAdd($this->hash . self::TTL_SUFFIX, [], ...$ttlparams); // The return value to the zAdd function never indicates whether the operation succeeded diff --git a/cache/stores/redis/tests/ttl_test.php b/cache/stores/redis/tests/ttl_test.php index 15c20b06f22..a02d58d6cbe 100644 --- a/cache/stores/redis/tests/ttl_test.php +++ b/cache/stores/redis/tests/ttl_test.php @@ -29,7 +29,7 @@ namespace cachestore_redis; * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @covers \cachestore_redis */ -class ttl_test extends \advanced_testcase { +final class ttl_test extends \advanced_testcase { /** @var \cachestore_redis|null Cache store */ protected $store = null; @@ -66,6 +66,15 @@ class ttl_test extends \advanced_testcase { } } + /** + * Test calling set_many with an empty array + * + * Trivial test to ensure we don't trigger an ArgumentCountError when calling zAdd with invalid parameters + */ + public function test_set_many_empty(): void { + $this->assertEquals(0, $this->store->set_many([])); + } + /** * Tests expiring data. */