【问题标题】:Redis session store on herokuHeroku 上的 Redis 会话存储
【发布时间】:2012-09-25 01:20:30
【问题描述】:

我正在尝试使用 redis 存储作为我在 heroku 上的会话存储。它在开发中运行良好,但我无法在 heroku 上建立 redis 连接。它正在尝试连接到 127.0.0.1 而不是正确的 redis 服务器。

错误:

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

我已将 heroku redis 配置设置为正确的服务器(不是真正用于会话存储,但已设置)

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'

环境.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/

当我进入 heroku 控制台时,我可以检查 APP_CONFIG['redis_server'],它被设置为 redis 服务器。

我还设置了一个 redis 连接,只是为了使用它。

redis.rb

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

当我对 heroku 进行安慰时,我可以执行以下操作并获得以下信息

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

任何帮助将不胜感激。谢谢。

【问题讨论】:

    标签: session heroku redis ruby-on-rails-3.2


    【解决方案1】:

    看起来像这样:

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

    应该是这样的:

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

    【讨论】:

    • 你也可以使用:redis_server作为参数。只是不是:server
    • 前段时间搞定了这个工作,你的评论是对的。我使用了 redis_server, GrnAuth::Application.config.session_store :redis_store, :redis_server => APP_CONFIG['redis_server'], key: '_grn_session'
    猜你喜欢
    • 2020-05-31
    • 1970-01-01
    • 2015-09-18
    • 1970-01-01
    • 1970-01-01
    • 2021-05-22
    • 2018-01-25
    • 2013-12-13
    • 1970-01-01
    相关资源
    最近更新 更多