Skip to content

Instantly share code, notes, and snippets.

@nateborr
Last active August 29, 2015 14:00
Show Gist options
  • Save nateborr/11308256 to your computer and use it in GitHub Desktop.
Save nateborr/11308256 to your computer and use it in GitHub Desktop.
Open redis-cli for a Redis Cloud Heroku add-on
heroku_app_name = ARGV[0]
# For Heroku's new hk command line tool:
#url_matcher = %r{REDISCLOUD_URL=redis://rediscloud:(\w+)@([\w-.]+):(\d+)}
#env_string = `hk -a #{heroku_app_name} | grep REDISCLOUD_URL`
url_matcher = %r{REDISCLOUD_URL:\s*redis://rediscloud:(\w+)@([\w\-.]+):(\d+)}
env_string = `heroku config -a #{heroku_app_name} | grep REDISCLOUD_URL`
env_settings = env_string.split('\n')
match_data = url_matcher.match(env_settings[0])
puts %{redis-cli -h #{match_data[2]} -p #{match_data[3]} -a #{match_data[1]}}
#!/bin/bash
`ruby redis_cloud_heroku_cli.rb $1`
@jasonaowen
Copy link

If you add

#!/usr/bin/env ruby

as the first line of the .rb file, you can mark it executable and you won't need the shell command any more.

Also, I needed to escape the - on line 7 to solve an empty range in char class error:

url_matcher = %r{REDISCLOUD_URL:\s*redis://rediscloud:(\w+)@([\w\-.]+):(\d+)}

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