Skip to content

Instantly share code, notes, and snippets.

@longlostnick
Created June 27, 2016 23:51
Show Gist options
  • Save longlostnick/e8d608b57f62be0ae86cd780c30a6527 to your computer and use it in GitHub Desktop.
Save longlostnick/e8d608b57f62be0ae86cd780c30a6527 to your computer and use it in GitHub Desktop.
Migrate redis key/values by key match
require 'redis'
redisSrc = Redis.connect url: "redis://<src>:6379"
redisDest = Redis.connect url: "redis://<dest>:6379"
redisSrc.keys("*").each do |key|
begin
data = redisSrc.dump key
ttl = redisSrc.pttl key # milleseconds
redisDest.restore key, ttl, data
rescue => e
p key, e
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment