$redis global variable with ruby on rails

后端 未结 6 617
灰色年华
灰色年华 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:31

    A more namespaced option to replace your global variable, you can create a method in a module

    module Caching
      def self.redis
        ... initialize/memoize/reconnect here...
      end
    end
    

    You than then call it with:

    Caching.redis

提交回复
热议问题