redis-rb / redis-client

Simple low level client for Redis 6+
MIT License
124 stars 60 forks source link

Recommened setup with Rails #138

Closed stoivo closed 1 year ago

stoivo commented 1 year ago

Hi,

How do you recommend setting this up with rails. I always wonder. How would bit be best to set this up. Global variables isn't great but it works...

byroot commented 1 year ago

Your question is too vague for me to answer with certainty.

But if the question is how to manage a redis connection pool to use across a Rails app, then something like:

module MyApp
  class << self
    attr_reader :redis_pool
  end
  @redis_pool = ConnectionPool.new(...) { Redis.new(...) }
end
stoivo commented 1 year ago

Yes , that was my question, how to manage it for a rails app.

I suspect you missed an end in you sample, @redis_pool should be in the class << self?

byroot commented 1 year ago

I suspect you missed an end in you sample

Indeed.

@redis_pool should be in the class << self?

Nope, that part wasn't a mistake :)