SuddenlyAwakened
SuddenlyAwakened

Reputation: 107

Redis session store on heroku

I am attempting to use redis store as my session store on heroku. It works fine in development but I am unable to get a redis connection on heroku. It is attempting to connect to a 127.0.0.1 instead of the correct redis server.

Error:

ActionView::Template::Error (Error connecting to Redis on 127.0.0.1:6379 (ECONNREFUSED)):

I have set the heroku redis config to the correct server (not really using for the session store but it is set)

REDISTOGO_URL: redis://redistogo:################################@carp.redistogo.com:9274/

session_store.rb

GrnAuth::Application.config.session_store :redis_store, :server => APP_CONFIG['redis_server'], key: '_grn_session'

environment.rb

# Load the rails application
require File.expand_path('../application', __FILE__)
require 'yaml'
APP_CONFIG = YAML.load_file("#{Rails.root}/config/config.yml")[Rails.env]

# Initialize the rails application
GrnAuth::Application.initialize!

config.yml

development:
  redis_server: redis://localhost:6379/

test:
  redis_server: redis://localhost:6379/

production:
  redis_server: redis://redistogo:################################@carp.redistogo.com:9274/

When I console in to heroku I can check APP_CONFIG['redis_server'] and it is set to the redis server.

I have also set up a redis connection just to use that works.

redis.rb

uri = URI.parse(ENV["REDISTOGO_URL"] || "redis://localhost:6379/" )
$redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)

When I console in to heroku I can do and get the following

irb(main):001:0> $redis
=> #<Redis client v3.0.1 for redis://carp.redistogo.com:9274/0>

Any help would be much appreciated. Thank you.

Upvotes: 1

Views: 1673

Answers (1)

Brian P O&#39;Rourke
Brian P O&#39;Rourke

Reputation: 646

It looks like this:

GrnAuth::Application.config.session_store :redis_store, :server => APP_CONFIG['redis_server'], key: '_grn_session'

Should instead be this:

GrnAuth::Application.config.session_store :redis_store, :servers => APP_CONFIG['redis_server'], key: '_grn_session'

Upvotes: 3

Related Questions