Skip to content

Instantly share code, notes, and snippets.

@robraux
Created January 10, 2013 04:00
Show Gist options
  • Save robraux/4499334 to your computer and use it in GitHub Desktop.
Save robraux/4499334 to your computer and use it in GitHub Desktop.
local res
local mover
-- step 1: ensure the target database is flushed
redis.call('select', ARGV[1])
redis.call('flushdb')
-- step 2: fetch keys to transfer from database 0, that is one and only master
redis.call('select', 0)
res = redis.call('keys', '*')
for key, value in pairs(res)
do
-- this select is imperative to make sure we don't start dumping from the target
redis.call('select', 0)
mover = redis.call('DUMP', value)
redis.call('select', ARGV[1])
-- do not care about TTLs, we are not testing that
redis.call('RESTORE', value, 0, mover)
end
-- leave redis select as you found it, just in case
redis.call('select', ARGV[1])
return 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment