2017-01-17 2 views

답변

1

Redis 데이터 형식을 복제/복사하는 가장 쉬운 방법은 DUMPRESTORE 명령 콤보입니다. 대부분의 경우 가장 빠릅니다.

앞뒤로 페이로드 전송을 방지하기 위해, 루아 스크립트 그것에 대해 확실히 가장 좋은 방법 (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"