diff --git a/ContentGrabbingJi-CacheStore-redis/src/main/lua/CheckElementContains.lua b/ContentGrabbingJi-CacheStore-redis/src/main/lua/CheckElementContains.lua new file mode 100644 index 0000000..1cd4e5b --- /dev/null +++ b/ContentGrabbingJi-CacheStore-redis/src/main/lua/CheckElementContains.lua @@ -0,0 +1,25 @@ +local key = tostring(KEYS[1]) +local value = ARGV[1] +local step = 175 + +if (key == nil) or (value == nil) then + return -1 +end + +if not (ARGV[2] == nil) then + step = tonumber(ARGV[2]) +end + +-- 步进循环搜索, 找到了立刻返回 +local listLength = redis.call('llen', key); +for i = 0, listLength, step do + local storeValue = redis.call("lrange", key, i, i + step) + for listIndex, v in ipairs(storeValue) do + if value == v then + return i + listIndex - 1; + end + end +end + +-- 如果没找到索引, 返回 0 +return -1 diff --git a/ContentGrabbingJi-CacheStore-redis/src/main/lua/RemoveElementByIndex.lua b/ContentGrabbingJi-CacheStore-redis/src/main/lua/RemoveElementByIndex.lua new file mode 100644 index 0000000..4a7d865 --- /dev/null +++ b/ContentGrabbingJi-CacheStore-redis/src/main/lua/RemoveElementByIndex.lua @@ -0,0 +1,28 @@ +local key = tostring(KEYS[1]) +local index = tonumber(ARGV[1]) + +if (key == nil) or (index == nil) then + return -1 +end + +local function getRandom(n) + local t = { + "0","1","2","3","4","5","6","7","8","9", + "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z", + "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z", + } + local s = "" + for _ = 1, n do + s = s .. t[math.random(#t)] + end; + return s +end; + +local flag = getRandom(24) + +if (redis.call("llen", key) <= index) or redis.call("lIndex", key, index) == nil then + return -1 +else + redis.call("lSet", key, index, flag); + return redis.call("lRem", key, 0, flag); +end