Skip to content

Instantly share code, notes, and snippets.

@bradhe
Created June 14, 2012 16:50
Show Gist options
  • Save bradhe/2931449 to your computer and use it in GitHub Desktop.
Save bradhe/2931449 to your computer and use it in GitHub Desktop.
Rake task for managing Redis, including connecting via CLI in current enviro.
require 'open3'
namespace :redis do
task :cli do
redis_config = File.expand_path('../../../config/redis.yml', __FILE__)
config_data = YAML.load_file(redis_config)
uri = URI.parse(config_data[ENV['RAILS_ENV'] || 'development'])
cli = File.expand_path('/path/to/redis-cli', __FILE__)
args = ["-h #{uri.host}", "-p #{uri.port}"]
args << "-a #{uri.password}" if uri.password
cmd = "#{cli} #{args.join(' ')}"
pid = fork { exec(cmd) }
Process.waitpid(pid)
end
task :flush_all => :environment do
print "Are you sure you want to do this? (Y/n) "
char = STDIN.getc
unless char.downcase == 'y'
$redis.flushall
puts "Redis has been flushed!"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment