mperham / connection_pool

Generic connection pooling for Ruby
MIT License
1.63k stars 143 forks source link

Create wrapper with existing pool #87

Closed etiennebarrie closed 8 years ago

etiennebarrie commented 8 years ago

I have a Rails app that is mostly using Redis for Sidekiq, but has a couple of other calls to Redis. I'd like to be able to use the same connection pool for these calls and Sidekiq, which would let me have only one Redis connection per thread.

e.g. with a setup like this

# initializers
threads = 5
$redis_pool = ConnectionPool.new(size: threads)
$redis = ConnectionPool::Wrapper.new(pool: $redis_pool)
Sidekiq.configure_client do |config|
  config.redis = $redis_pool
end

I could have this code in a thread and only have one Redis connection checked in at the end.

# app code
$redis.ping
MyWorker.perform_async(1, 2, 3)

Am I missing something? Could this be useful for ConnectionPool?

mperham commented 8 years ago

Neat idea.