2017-01-17 53 views

回答

1

复制/复制任何Redis数据类型的最简单方法是使用​​3210和​​命令组合。这在大多数情况下也是最快的。

为了避免发送有效载荷来回,一个Lua脚本,绝对是最好的方式(https://gist.github.com/itamarhaber/d30b3c40a72a07f23c70):

-- @desc: The fastest, type-agnostic way to copy a Redis key 
-- @usage: redis-cli --eval copy_key.lua <source> <dest> , [NX] 

local s = KEYS[1] 
local d = KEYS[2] 

if redis.call("EXISTS", d) == 1 then 
    if type(ARGV[1]) == "string" and ARGV[1]:upper() == "NX" then 
    return nil 
    else 
    redis.call("DEL", d) 
    end 
end 

redis.call("RESTORE", d, 0, redis.call("DUMP", s)) 
return "OK"