Skip to content

Instantly share code, notes, and snippets.

@ssaunier
Created August 2, 2015 10:58
Show Gist options
  • Save ssaunier/59832bc7d776a7d9f8de to your computer and use it in GitHub Desktop.
Save ssaunier/59832bc7d776a7d9f8de to your computer and use it in GitHub Desktop.
Connect to Heroku RedisCloud as `redis-cli`
#!/usr/bin/env ruby
url_matcher = %r{REDISCLOUD_URL:\s*redis://rediscloud:(\w+)@([\w\-.]+):(\d+)}
env_string = `heroku config | grep REDISCLOUD_URL`
env_settings = env_string.split('\n')
match_data = url_matcher.match(env_settings[0])
db = ARGV[0] || 0
command = %{redis-cli -h #{match_data[2]} -p #{match_data[3]} -a #{match_data[1]} -n #{db}}
system command
@ssaunier
Copy link
Author

ssaunier commented Aug 2, 2015

Put that in your ~/.bin folder and add it to your path. Then in any git repo with a heroku remote, you can just run:

$ redis_cloud_heroku_cli.rb

@ethanpooley
Copy link

Thanks! Also, heroku config:get REDISCLOUD_URL returns just the URL. So I compacted a bit:

url_matcher = %r{redis://rediscloud:(\w+)@([\w\-.]+):(\d+)}
match_data = url_matcher.match(`heroku config:get REDISCLOUD_URL`)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment