From f1e76092a0183d3d8e1226b4671a725434771d2b Mon Sep 17 00:00:00 2001 From: LamGC Date: Mon, 11 Jan 2021 16:24:55 +0800 Subject: [PATCH] =?UTF-8?q?[Fix]=20CacheStore-Redis=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=20RemoveElementByIndex=20=E8=84=9A=E6=9C=AC=E4=B8=AD=E5=AF=B9?= =?UTF-8?q?=E6=97=A0=E6=95=88=E9=A1=B9=E5=88=A4=E6=96=AD=E7=9A=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [Fix] RemoveElementByIndex.lua 修复范围溢出, 不存在键检查失效的问题; --- .../src/main/lua/RemoveElementByIndex.lua | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/ContentGrabbingJi-CacheStore-redis/src/main/lua/RemoveElementByIndex.lua b/ContentGrabbingJi-CacheStore-redis/src/main/lua/RemoveElementByIndex.lua index d16a416..1949646 100644 --- a/ContentGrabbingJi-CacheStore-redis/src/main/lua/RemoveElementByIndex.lua +++ b/ContentGrabbingJi-CacheStore-redis/src/main/lua/RemoveElementByIndex.lua @@ -1,10 +1,3 @@ -local key = tostring(KEYS[1]) -local index = tonumber(ARGV[1]) - -if (key == nil) or (index == nil) then - return 0 -end - local function getRandom(n) local t = { "0","1","2","3","4","5","6","7","8","9", @@ -16,13 +9,23 @@ local function getRandom(n) s = s .. t[math.random(#t)] end; return s -end; +end -local flag = getRandom(24) +local key = tostring(KEYS[1]) +local index = tonumber(ARGV[1]) -if (redis.call("llen", key) <= index) or redis.call("lIndex", key, index) == nil then +if (key == nil) or (index == nil) or (redis.call("exists", key) == false) then + return 0 +end + +local listLength = redis.call("llen", key) +if listLength == 0 then + return 0 +end +if (index < 0) or (index >= listLength) or redis.call("lIndex", key, index) == nil then return 0 else + local flag = getRandom(24) redis.call("lSet", key, index, flag); return redis.call("lRem", key, 0, flag); end