我可以将redis-cli与连接URL一起使用吗?

Ale*_*ino 14 connection-string heroku redis redis-cli

psql通过向连接字符串提供它而不必在不同的参数中打破它,我习惯使用它,也就是说,

psql postgres://<username>:<password>@<host>:<port>
Run Code Online (Sandbox Code Playgroud)

例如,当我从Heroku获得这样的字符串时,这很有用.我可以做类似的事redis-cli吗?我想直接向它提供一个连接字符串,例如当我安装Redis插件时作为环境变量存储在Heroku上的连接字符串.那可能吗?我想要使​​用的语法示例:

redis-cli redis://<username>:<password>@<host>:<port>
Run Code Online (Sandbox Code Playgroud)

Ita*_*ber 19

不,目前(v3.2.1)redis-cli不支持URI连接模式.如果需要,可以在Redis存储库中为该功能创建功能或提取请求.

更新:-u选项随Redis 4.0发布,请参阅发行说明.

  • 并感谢您创建拉取请求:https://github.com/antirez/redis/pull/3409 (2认同)
  • @AlessandroCosentino 感谢您更新回复 - 看起来我遵守了我的承诺(现在我正在尝试使用 redis-benchmark 做同样的事情:P)) (2认同)

Bru*_* A. 8

对于那些无法等待下一个Redis版本将无法更新其redis-cli的用户,我做了一个简单的bash函数,该函数似乎适用于我的情况(Heroku)。这将被添加到~/.bash_profile或中~/.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
}
Run Code Online (Sandbox Code Playgroud)

然后,我可以在终端中键入以下内容:

redis-url redis://rediscloud:mysupersecurepassword@hostname.com:1234
Run Code Online (Sandbox Code Playgroud)