Can I use redis-cli with a connection URL?
Solution 1
No, at the moment (v3.2.1) redis-cli does not support the URI connection schema. If you want, you can make a feature or pull request for that in the Redis repository.
UPDATE:
The -u
option was released with Redis 4.0, see Release notes. For example:
redis-cli -u redis://user:pass@host:6379/0
Solution 2
For those who cannot wait for the next Redis release won't be able to update their redis-cli, I made a simple bash function that seems to work for my case (Heroku). This is to be added to ~/.bash_profile
or ~/.bashrc
:
function redis-url() {
# Get the first argument as the URL variable
url=$1
# Parse and generate the command: redis-cli -h [hostname] -p [port] -a [password]
cmd=`echo $url | sed 's_redis://\(.*\):\(.*\)@\(.*\):\(.*\)_redis-cli -h \3 -p \4 -a \2_'`
# Run the command
$cmd
}
I can then type the following in my terminal:
redis-url redis://rediscloud:[email protected]:1234
Alessandro Cosentino
Classical and Quantum Computer scientist. Posts and commments are my opinions and are not sponsored or endorsed by my employer.
Updated on April 06, 2021Comments
-
Alessandro Cosentino about 3 years
I am used to
psql
which I can use by feeding it the connection string without having to break it in different arguments, that is,psql postgres://<username>:<password>@<host>:<port>
This is useful when I have such string from Heroku, for example. Can I do something similar with
redis-cli
? I want to feed it directly a connection string, such as the one that is stored on Heroku as environment variable when I install a Redis add-on. Is that possible? Example of the syntax I would like to use:redis-cli redis://<username>:<password>@<host>:<port>