连接远程redis服务器 [英] Connecting to remote redis server

查看:59
本文介绍了连接远程redis服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 redis.conf 中进行一些更改,以便每当我输入 redis-cli 时,它都会将我连接到安装在远程服务器上的 redis.

I wanted to make some changes in redis.conf, so that whenever i type redis-cli it connects me to redis installed on remote server.

我知道我们可以通过以下方式连接到远程服务器上安装的 redis:

I know that we can connect to redis installed on remote server by :

redis-cli -h 'IP-Address-Of-Server'. 

但实际上,我有一些 bash 脚本,并且在这些脚本中,我在很多地方都使用了 redis-cli.因此,与其在每个文件中用 redis-cli -h 'IP-Address-Of-Server' 替换 redis-cli,我想以某种方式更改 redis 配置,以便默认情况下它将我连接到远程服务器.我希望这是有道理的:)

But actually, I have some bash scripts and in those scripts i have used redis-cli at many place. So instead of replacing redis-cli with redis-cli -h 'IP-Address-Of-Server' in each file, I wanted to somehow change redis configuration, so that by default it connects me to the remote server. I hope it make sense :)

推荐答案

就像 Tommaso 所说的,这不是为了这个目的而去接触 redis conf 的充分理由.相反,您可以做的是在 bash 脚本中使用环境变量来执行命令,然后在您直接使用 redis-cli 的任何地方使用该环境变量.

Like Tommaso said, this is no good reason to touch the redis conf for this purpose. Instead what you can do is use environment variables to in your bash scripts to execute the command and then use that environment variable wherever you've used redis-cli directly.

例如.$REDIS_CONNECTION="redis-cli -h "

For eg. $REDIS_CONNECTION="redis-cli -h "

如果在未来的任何时间点,您决定更改要连接的主机,只需更改 env 变量值即可.

If at any future point in time, you decide to change the host you want to connect to, its simply a matter of changing the env variables value.

在所有文件中使用 sed 将环境变量替换为 redis-cli 非常简单.所以这应该不会太麻烦.

Replacing redis-cli with the environment variable is pretty straightforward with sed in all the files. So that shouldn't be much of a hassle.

这篇关于连接远程redis服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆