$redis global variable with ruby on rails

后端 未结 6 618
灰色年华
灰色年华 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条回答
  •  悲哀的现实
    2021-02-01 15:28

    if you don't already use another Rails.cache I advise you to just use that mechanism with redis.

    The gem redis-store makes this realy easy (https://github.com/redis-store/redis-store)

    This way you can just do Rails.cache.reconnect and all is dandy

    https://github.com/redis-store/redis-store/issues/21#issuecomment-948569

    It also allows you to use the awesome Rails.cache API, which has some neat features: http://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html

提交回复
热议问题