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

  • 相关阅读:
    79. Word Search
    97. Interleaving String
    74. Search a 2D Matrix
    73. Set Matrix Zeroes
    72. Edit Distance
    71. Simplify Path
    64. Minimum Path Sum
    shell编程 备份mysql数据库并发送到另一个服务器
    linux 命令执行的判断依据: ;,&&,||
    linux 数据流重定向
  • 原文地址:https://www.cnblogs.com/paulversion/p/13843034.html
Copyright © 2011-2022 走看看