Raketask for connecting to Redis on Heroku
Assuming redis-cli is installed on your computer and you're using OpenRedis. If not, replace OPENREDIS_URL with the correct Heroku config variable that contains a Redis connection string.
desc 'Connect to Redis (production)'
task :redis do
redis_uri = `heroku config:get OPENREDIS_URL`
pattern = /redis:\/\/:(\S+)@(\S+):(\d+)/
redis_uri[pattern]
exec "redis-cli -a #{1ドル} -h #{2ドル} -p #{3ドル}"
end
Execute by running rake redis
The regex pattern will capture the password, the host and the port into 1ドル, 2ドル and 3ドル respectively. exec will replace the currently running process with that of the command being executed, in this case redis-cli.
Perhaps a bit Perl-ish code, but it gets the job done. :)
Update: OpenRedis is using a proxy these days. For details, see http://gist.io/4198977
Written by Lennart Fridén
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#