Skip to content

Instantly share code, notes, and snippets.

@nono
Created November 28, 2011 23:29
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save nono/1402597 to your computer and use it in GitHub Desktop.
Save nono/1402597 to your computer and use it in GitHub Desktop.
Export data from redis to a plain text files
#!/usr/bin/env ruby
require "redis"
redis = Redis.new
redis.keys("*").each do |key|
val = case redis.type(key)
when "string"
redis.get key
when "list"
redis.lrange key, 0, -1
when "hash"
redis.hgetall key
when "set"
redis.smembers key
when "sortedset"
redis.zrange key, 0, -1
else
"unknown"
end
puts "#{key}: #{val}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment