Skip to content

Instantly share code, notes, and snippets.

@taisyo7333
Last active January 23, 2017 07:11
Show Gist options
  • Save taisyo7333/03ff38d4c9086eebb3dbd72468b56d89 to your computer and use it in GitHub Desktop.
Save taisyo7333/03ff38d4c9086eebb3dbd72468b56d89 to your computer and use it in GitHub Desktop.
AWS Elastic Cache Redis 対応

概要

Redisに接続しようとするとエラーになる

環境

  • AWS
    • Elastic Beanstalk (Multi-Containers-Docker)
    • RDS
    • Elastic Cache (Redis)
  • Ruby
  • Rails
  • React

現象

ActionView::Template::Error (Error connecting to Redis on xxxxxx.pen1pi.ng.0001.usw2.cache.amazonaws.com:6379 (Redis::TimeoutError)):
    4:   <title>App</title>
    5:   <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
    6:   <%= javascript_include_tag 'common', 'data-turbolinks-track' => true %>
    7:   <%= csrf_meta_tags %>
    8: </head>
    9: <body>
   10: 
  app/views/layouts/application.html.erb:7:in `_app_views_layouts_application_html_erb___finger_print_here'
  • VPCのセキュリティグループ設定が必要。
  • 同一VPC内であればEC2とElasticCacheは接続可能。 * inbound で 6379ポートをOPENにしておく必要がある。

 

環境変数 REDIS_URL を使わない。

下記の処理を削除したら意図する挙動になった。

path

config/initializers/redis.rb

source

Redis.current = Redis.new(url: ENV["REDIS_URL"])

Reference URL

http://docs.aws.amazon.com/ja_jp/AmazonElastiCache/latest/UserGuide/GettingStarted.AuthorizeAccess.html#GettingStarted.AuthorizeAccess.VPC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment