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

  • 相关阅读:
    SpringDataJpa
    #pragma pack(n)的使用
    jquery中的ajax方法参数
    rapidjson的使用
    Linux下Qt安装
    jsoncpp 0.5 ARM移植
    GoAhead2.5移植到ARM教程
    Qt 4.7.2移植到ARM教程
    虚函数与纯虚函数的区别
    海康、大华IpCamera RTSP地址和格式
  • 原文地址:https://www.cnblogs.com/paulversion/p/13843034.html
Copyright © 2011-2022 走看看