Skip to content

Commit 0b042d2

Browse files
Merge pull request #163 from nemphys/lua-clean-fix
Fix bug in lua clean script (tags not removed from global list of tags)
2 parents 1132d90 + b19e3a5 commit 0b042d2

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

Cm/Cache/Backend/Redis.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Cm_Cache_Backend_Redis extends Zend_Cache_Backend implements Zend_Cache_Ba
5656
const DEFAULT_CONNECT_RETRIES = 1;
5757

5858
const LUA_SAVE_SH1 = '1617c9fb2bda7d790bb1aaa320c1099d81825e64';
59-
const LUA_CLEAN_SH1 = '42ab2fe548aee5ff540123687a2c39a38b54e4a2';
59+
const LUA_CLEAN_SH1 = 'a6d92d0d20e5c8fa3d1a4cf7417191b66676ce43';
6060
const LUA_GC_SH1 = 'c00416b970f1aa6363b44965d4cf60ee99a6f065';
6161

6262
/** @var Credis_Client */
@@ -763,21 +763,24 @@ protected function _removeByMatchingAnyTags($tags)
763763
if ($this->_useLua) {
764764
$tags = array_chunk($tags, $this->_sunionChunkSize);
765765
foreach ($tags as $chunk) {
766-
$chunk = $this->_preprocessTagIds($chunk);
767-
$args = array(self::PREFIX_KEY, self::SET_TAGS, self::SET_IDS, ($this->_notMatchingTags ? 1 : 0), (int) $this->_luaMaxCStack);
766+
$args = array(self::PREFIX_TAG_IDS, self::PREFIX_KEY, self::SET_TAGS, self::SET_IDS, ($this->_notMatchingTags ? 1 : 0), (int) $this->_luaMaxCStack);
768767
if ( ! $this->_redis->evalSha(self::LUA_CLEAN_SH1, $chunk, $args)) {
769768
$script =
770-
"for i = 1, #KEYS, ARGV[5] do ".
771-
"local keysToDel = redis.call('SUNION', unpack(KEYS, i, math.min(#KEYS, i + ARGV[5] - 1))) ".
772-
"for _, keyname in ipairs(keysToDel) do ".
773-
"redis.call('DEL', ARGV[1]..keyname) ".
774-
"if (ARGV[4] == '1') then ".
775-
"redis.call('SREM', ARGV[3], keyname) ".
776-
"end ".
777-
"end ".
778-
"redis.call('DEL', unpack(KEYS, i, math.min(#KEYS, i + ARGV[5] - 1))) ".
779-
"redis.call('SREM', ARGV[2], unpack(KEYS, i, math.min(#KEYS, i + ARGV[5] - 1))) ".
780-
"end ".
769+
"for i = 1, #KEYS, ARGV[6] do " .
770+
"local prefixedTags = {} " .
771+
"for x, tag in ipairs(KEYS) do " .
772+
"prefixedTags[x] = ARGV[1]..tag " .
773+
"end " .
774+
"local keysToDel = redis.call('SUNION', unpack(prefixedTags, i, math.min(#prefixedTags, i + ARGV[6] - 1))) " .
775+
"for _, keyname in ipairs(keysToDel) do " .
776+
"redis.call('DEL', ARGV[2]..keyname) " .
777+
"if (ARGV[5] == '1') then " .
778+
"redis.call('SREM', ARGV[4], keyname) " .
779+
"end " .
780+
"end " .
781+
"redis.call('DEL', unpack(prefixedTags, i, math.min(#prefixedTags, i + ARGV[6] - 1))) " .
782+
"redis.call('SREM', ARGV[3], unpack(KEYS, i, math.min(#KEYS, i + ARGV[6] - 1))) " .
783+
"end " .
781784
"return true";
782785
$this->_redis->eval($script, $chunk, $args);
783786
}

0 commit comments

Comments
 (0)