この記事では hubot-redis-brain 0.0.3 を使用しています
hubot-redis-brain のRedisサーバに Azure Redis Cache を使用してみました。
(SSLアクセスするようにした方が良いかなと思いましたがいったんhttpで進めました)
Azure Portal で Azure Redis Cache の接続情報を見ると、接続時にパスワードの指定が必要です。
hubot-redis-brain の使用するRedisサーバをどのように設定するのか、調べながら進めました。
結論
環境変数 REDIS_URL に redis://${auth}@${host}:${port}/${prefix}
の形式で設定
パラメータ | デフォルト | 設定値 |
---|---|---|
auth | パスワード認証が必要な場合は、 :${password} で指定。パスワード前に':'がある点に注意!
|
|
host | RedisサーバのFQDN、IPアドレス | |
port | 6379 | ポート |
prefix | hubot | Redisに投入する際のキーのプリフィックス |
はまった流れ
まずは hubot-redis-brain が使用するRedisサーバの設定方法を調べました。
https://github.com/hubot-scripts/hubot-redis-brain を見ると、以下のような記載がありました。
hubot-redis-brain requires a redis server to work. It uses the REDIS_URL environment variable for determining where to connect to. The default is on localhost, port 6379 (ie the redis default).
The following attributes can be set using the REDIS_URL
authentication
hostname
port
key prefix
For example, export REDIS_URL=redis://passwd@192.168.0.1:16379/prefix would authenticate with password, connecting to 192.168.0.1 on port 16379, and store data using the prefix:storage key.
REDIS_URLに redis://${password}@${host}:${port}/${prefix}
の形で設定すれば良さそうなので早速設定してみました。
ログを見ると接続には成功しているようですが、Redisに対して情報が投入されません。
INFO hubot-redis-brain: Discovered redis from REDIS_URL environment variable
DEBUG hubot-redis-brain: Successfully connected to Redis
通常、URLに認証情報を埋め込む場合は http://user:password@example.com/
のように書きます。
ホスト情報の前に
hubot-redis-brain のコードを見てみると${password}部分は認証情報としてみており、それを':'でsplitして2番目のパラメータをパスワードとして利用していました。
redis://:${password}@${host}:${port}/${prefix}
の形式で設定してみると、Redisに情報が投入され始めました!
ログにも認証に成功した旨が表示されました。
INFO hubot-redis-brain: Discovered redis from REDIS_URL environment variable
INFO hubot-redis-brain: Successfully authenticated to Redis
DEBUG hubot-redis-brain: Successfully connected to Redis
INFO hubot-redis-brain: Data for hubot brain retrieved from Redis
めでたしめでたし。