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)
对于那些无法等待下一个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)
| 归档时间: |
|
| 查看次数: |
8898 次 |
| 最近记录: |