Quantcast
Channel: Active questions tagged redis+ruby-on-rails - Stack Overflow
Viewing all articles
Browse latest Browse all 873

Sharing a connection pool for all Rails uses of Redis

$
0
0

Summary: I'm using a single Redis instance for the Rails cache, actioncable and (non-cache) use in my rails code. Should all these uses share a single connection pool and if so how can I config this to make it happen since there seem to be totally different ways to setup the pooling for each?



Details follow since people seem to like to see them.

I'm using redis as the adapter for rails cache using the following config.

  config.cache_store = :redis_cache_store, {    url: "redis://XXX.net:6379/0",    pool_size: ENV.fetch('RAILS_MAX_THREADS') { 5 },    password: Rails.application.credentials.dig(:redis, :password),    expires_in: 24.hours,    pool_timeout: 5  }

I've set the expires_in option so that I can set the option in my redis config to evict keys with expiration set so I can use the same redis instance for both cache and non-cache data. Now, I want to also access REDIS directly for non-cache related tasks via something like the example config below

pool_size = ENV.fetch("RAILS_MAX_THREADS", 5)redis_pool = ConnectionPool.new(size: pool_size) do  Redis.new(    url: "redis://XXX.net:6379/0",  )end

But I'm not sure if that is correct. Shouldn't I be sharing a connection pool between the cache_store connections and the other connections to Redis? If so, how can I do this?

To complicate matters further I'm also using Redis for actioncable via a config like

production:  adapter: redis  url: <%= ENV.fetch("REDIS_URL") { "redis://XXX.net:6379/0" } %>  password: <%= Rails.application.credentials.dig(:redis, :password) %>

I've seen suggestions that actioncable will automatically handle connection pooling with Redis if I'm using the connection_pool gem (is this right?) but I feel like all these connections should be drawing from the same pool. If so how can I make that happen?


Viewing all articles
Browse latest Browse all 873

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>