Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Heroku plugin for redis-cli.

  • Loading branch information...
commit e2cb925eff8b87043cad9a565039411b60153262 0 parents
@ConradIrwin ConradIrwin authored
Showing with 33 additions and 0 deletions.
  1. +7 −0 init.rb
  2. +26 −0 lib/redis_console.rb
7 init.rb
@@ -0,0 +1,7 @@
+require File.dirname(__FILE__) + '/lib/redis_console.rb'
+
+Heroku::Command::Help.group('Redis Console') do |group|
+ group.command 'redis:cli [--db REDIS_URL] *args', 'Open a redis-cli shell to the database'
+ group.command 'redis:info [--db REDIS_URL]', 'Get INFO for the redis database'
+ group.command 'redis:monitor [--db REDIS_URL]', 'MONITOR the redis database'
+end
26 lib/redis_console.rb
@@ -0,0 +1,26 @@
+require 'uri'
+class Heroku::Command::Redis < Heroku::Command::Base
+
+ def cli(*queries)
+ # Must remember to extract these so they don't get passed to redis-cli
+ db = extract_option("--db") || 'REDISTOGO_URL'
+ app = extract_app
+
+ redis_url = heroku.config_vars(app)[db]
+ return puts "No such redis (#{db}), try setting --db REDIS_URL." unless redis_url
+ uri = URI.parse(redis_url)
+
+ cmd = ["redis-cli"]
+ cmd << "-a" << uri.password if uri.password
+ cmd << "-h" << uri.host if uri.host
+ cmd << "-p" << uri.port.to_s if uri.port
+ cmd << "-n" << uri.path.gsub("/", "").to_i.to_s
+
+ # queries are set by monitor and info, and args are remaining command line arguments
+ # passed to heroku redis.
+ exec *(cmd + args + queries)
+ end
+
+ def monitor; cli 'monitor'; end
+ def info; cli 'info'; end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.