zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    [每日一题]石子合并 -- 区间DP
    [每日一题]: 最长上升子序列 AND 最长不上升子序列
    [每日一题]:最大子矩阵和
    入门DP--最大子段和
    [转载]:正确的提问方式
    springmvc.xml
    service层springservice.xml文件
    aop切面配置
    配置事务通知
    短信验证
  • 原文地址:https://www.cnblogs.com/paulversion/p/13843034.html
Copyright © 2011-2022 走看看