Use global or constant variable in Ruby/Rails? -


say have connection memcache or redis... style preferred , why?

memcache = memcache.new(...) redis = redis.new(...) 

or

$memcache = memcache.new(...) $redis = redis.new(...) 

you might want use redis.current more info here

for example, in initializer:

redis.current = redis.new(host: 'localhost', port: 6379) 

and in other classes:

def stars   redis.smembers("stars") end  private  def redis   redis.current end 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -