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>
To start Redis client, open the terminal and type the command redis-cli. This will connect to your local server and now you can run any command.
DESCRIPTION. The URI::redis class supports URI objects belonging to the redis and redis+unix URI scheme. Such URLs are used to encode connection info ( redis : host, port, password, database, redis+unix : socket path, password, database) to Redis servers.
It has two main modes: an interactive Read Eval Print Loop (REPL) mode where the user types Redis commands and receives replies, and a command mode where redis-cli is executed with additional arguments and the reply is printed to the standard output.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With