From f414802c631a26ad7e16050ea524eec817559c7b Mon Sep 17 00:00:00 2001 From: LamGC Date: Sat, 16 Jan 2021 01:43:00 +0800 Subject: [PATCH] =?UTF-8?q?[Add]=20CacheStore-Redis=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E5=89=8D=E7=BC=80=E9=94=AE=E5=90=8D=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E8=84=9A=E6=9C=AC,=20=E4=BB=A5=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E5=B8=A6=E6=9C=89=E5=8E=9F=E5=AD=90=E6=80=A7=E7=9A=84=20RedisC?= =?UTF-8?q?acheStore.clear=20=E6=93=8D=E4=BD=9C;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [Add] RemoveKeysByPrefix.lua 添加用于实现 RedisCacheStore.clear 操作的脚本; --- .../src/main/lua/RemoveKeysByPrefix.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 ContentGrabbingJi-CacheStore-redis/src/main/lua/RemoveKeysByPrefix.lua diff --git a/ContentGrabbingJi-CacheStore-redis/src/main/lua/RemoveKeysByPrefix.lua b/ContentGrabbingJi-CacheStore-redis/src/main/lua/RemoveKeysByPrefix.lua new file mode 100644 index 0000000..48c0a8e --- /dev/null +++ b/ContentGrabbingJi-CacheStore-redis/src/main/lua/RemoveKeysByPrefix.lua @@ -0,0 +1,18 @@ +local keyPrefix = tostring(KEYS[1]) + +if (keyPrefix == nil) then + return false +end + +if (string.sub(keyPrefix, string.len(keyPrefix)) ~= "*") then + keyPrefix = keyPrefix .. "*" +end + + +local keys = redis.call("KEYS", keyPrefix) +local count = 0; +for _, v in ipairs(keys) do + count = count + redis.call("DEL", v) +end + +return count