redis list 分片 當redis的list數據量比較大時采用分片處理


for v in pairs(ARGV) do
redis.debug(ARGV[v])
end
redis.debug(redis.call("GET",KEYS[1]))

local function slice(list_key,argv_list)
local type_result = redis.call("type",list_key)
if type_result["ok"] == 'list' then

local reverse_flag = #argv_list >= 3 and tonumber(ARGV[3]) and toumber(ARGV[3]) < 0
local start = 1
if tonumber(ARGV[1]) then start = tonumber(ARGV[1]) end
local end_ = tonumber(redis.call("LLEN",list_key))
if tonumber(ARGV[2]) then end_ = tonumber(ARGV[2]) end
local step = 1
if #argv_list >= 3 and tonumber(ARGV[3]) then
step = tonumber(ARGV[3])
end
--儲存分片結果
local result = {}
local result_index = 1
print('start:'..start..'end: '..end_..'step:'..step)
local for_start = start
local for_end = end_
if reverse_flag then
if not tonumber(ARGV[1]) then for_start = tonumber(redis.call("LLEN",list_key)) end
for_end = for_end + 1
else
for_end = for_end - 1
end
print("for_start"..for_start..'for_end:'..for_end..'step:'..step)
for var=for_start,for_end,step do
result[result_index] = list[var]
result_index = result_index + 1
end
return result
else
return list_key .. "不是list類型"
end
end

 

local result_list = slice(KEYS[1],ARGV)

for k,v in pairs(result_list) do
print(k.."--->"..v)
end

return result_list


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM