$redis global variable with ruby on rails

后端 未结 6 620
灰色年华
灰色年华 2021-02-01 14:35

I am using redis as a read cache. I have created an initializer

config/initializer/redis.rb

$redis = Redis.new(:host => ENV[\"REDIS_HOST\"], :port =&         


        
6条回答
  •  -上瘾入骨i
    2021-02-01 15:28

    According to this Heroku, you don't need to add $redis to your Unicorn:

    No special setup is required when using Redis Cloud with a Unicorn server. Users running Rails apps on Unicorn should follow the instructions in the Configuring Redis from Rails section and users...

    Here's all the "Configuring Redis from Rails section" has for before Rails 4 (besides the Gemfile and some other pre-Rails 3 stuff):

    # config/initalizers/redis.rb
    
    if ENV["REDISCLOUD_URL"]
      uri = URI.parse(ENV["REDISCLOUD_URL"])
      $redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
    end
    

    It doesn't really give an explanation as to why "no special setup is required".

提交回复
热议问题