Heroku: 使用CLI访问Redis并进行命令操作

这是关于如何连接到Heroku上的Redis,并直接从CLI执行Redis操作命令的笔记。

我在Heroku的Add-on中尝试使用Redis,但是很难找到从本地直接连接到Redis的方法,让我有些沮丧。
Heroku很方便,但是文档很难找到。

在Heroku上有一些Redis托管服务作为Add-ons。

    Add-ons
DB種類.PNG
    今回は、Redis To Go を使いました。

使用命令行连接到 Redis 的功能。

(Note: This is machine-translated output, and, therefore, may not be perfect.)

进入自己的Heroku应用目录并安装heroku-redis插件

以下是插件的页面链接:
这个插件不是为Redis To Go设计的,而是为Heroku Redis设计的。
不过,Redis To Go的CLI工具也可以使用。

heroku plugins:install heroku-redis
heroku redis:cli

只需要一个选项!

于是….

heroku redis:cli
 ▸    WARNING: Insecure Action
 ▸    All data, including the redis password, will be unencrypted.
 ▸    To proceed, type hogehoge or re-run this command with --confirm hogehoge

> hogehoge

Connecting to: REDIS_URL
ec2-54-221-206-137.compute-1.amazonaws.com:6379> PING
PONG
ec2-54-221-206-137.compute-1.amazonaws.com:6379>

可以通过从本地直接访问Heroku上的Redis来实现类似的功能。
它会读取环境变量REDIS_URL并连接到相应的Redis,因此你只需要在每个应用程序的文件夹中执行命令,
就可以自动访问应用程序正在使用的Redis。

剩下的就任何您喜欢的命令都可以。

    コマンドリファレンス