local src_hash = KEYS[1] .. ":Q"
local dst_hash = KEYS[2] .. ":Q"
local body = redis.call("HGET", src_hash, ARGV[1])
if not body then
return 0
end
local rc = redis.call("HGET", src_hash, ARGV[1] .. ":rc")
local fr = redis.call("HGET", src_hash, ARGV[1] .. ":fr")
local time = redis.call("TIME")
local score
if ARGV[2] == "1" then
score = tonumber(time[1]) * 1000000 + tonumber(time[2])
else
score = tonumber(time[1]) * 1000 + math.floor(tonumber(time[2]) / 1000)
end
redis.call("ZADD", KEYS[2], score, ARGV[1])
redis.call("HSET", dst_hash, ARGV[1], body)
if rc then
redis.call("HSET", dst_hash, ARGV[1] .. ":rc", rc)
redis.call("HSET", dst_hash, ARGV[1] .. ":fr", fr or score)
end
redis.call("HINCRBY", dst_hash, "totalsent", 1)
redis.call("ZREM", KEYS[1], ARGV[1])
redis.call("HDEL", src_hash, ARGV[1], ARGV[1] .. ":rc", ARGV[1] .. ":fr")
return 1