Looks like this does what I need:
eval "
redis.call('DEL','final')
local set=redis.call('ZREVRANGE','out',0,4,'withscores')
for i = 1, #set/2 do
set[2*i-1], set[2*i] = set[2*i], set[2*i-1]
end
return redis.call('ZADD','final',unpack(set))
" 0
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…