0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

RailsでHotwire(websocket)使ったら、HerokuのRedisで接続エラーになった

Last updated at Posted at 2024-10-02

起こったこと

RailsアプリでHotwireのWebSocketを導入時に、Redisが必要になった。
HerokuそれをHerokuにデプロイしたら、Redisを使う場面で以下のエラーになった。

redis::CannotConnectError (SSL_connect returned=1 errno=0 peeraddr=34.232.151.103:20700 state=error: certificate verify failed (self-signed certificate in certificate chain) (rediss://ec2-XXXXXXXXXX.amazonaws.com:000000)):

Herokuの公式ドキュメントにある、RailsでRedisに接続するためのコードは実装していた。

config/initializers/redis.rb
$redis = Redis.new(url: ENV["REDIS_URL"], ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE })

環境変数、REDIS_URLREDIS_TLS_URLなどの設定も問題なさそう。

結論

WebSocketを使う場合、以下の設定も必要でした。

config/cable.yml
production:
  adapter: redis
  url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
  channel_prefix: name_production
  ssl_params:
    verify_mode: <%= OpenSSL::SSL::VERIFY_NONE %>

単純にHotwireを使うだけではRedisは必要ない。

▼実装の参考にした記事
https://zenn.dev/shita1112/books/cat-hotwire-turbo/viewer/turbo-streams-websocket

HotwireでWebSocketを使っていたからRedisが必要だった。
Hotwireだから設定が必要なのではなく、WebSocketを使っていたから設定が必要だと気付ければ、もっと早く解決できたかもしれない。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?