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