Skip to content

Instantly share code, notes, and snippets.

@todgru
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save todgru/bc2d0f8bf586a8669e85 to your computer and use it in GitHub Desktop.

Select an option

Save todgru/bc2d0f8bf586a8669e85 to your computer and use it in GitHub Desktop.
ruby hack to copy a subset of redis keys from an old server to a new server

Redis Key Copy

require "redis"

# old redis server with keys we want to copy
old = Redis.new(:url => "redis://:password@url:6379/0")

# new server address
new = Redis.new(:url => "redis://127.0.0.1:6379/0")

# the "name" keys we want to copy from the old server
# could be explicit here. A wild card works for a small set.
name_keys = old.keys("name_*")

name_keys.each do |key|
  old.hgetall("#{key}").each do |k,v|
    aws.hset("#{key}", k, v)
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment