New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to inject underlying Redis object, as in the case of connection pooling #22

Closed
findchris opened this Issue Oct 2, 2014 · 4 comments

Comments

Projects
None yet
2 participants
@findchris

findchris commented Oct 2, 2014

Hi there.

When using redis-rb directly, I can do something like:

redis = ConnectionPool::Wrapper.new(size: 5, timeout: 5) { Redis.new(url: ...) }

I've also issued explicit redis.quit to keep connection usage low.

Is it possible to do something similar with redis-store/redis-activesupport?

Thanks.

@findchris

This comment has been minimized.

findchris commented Oct 2, 2014

As of now, monkey patching seems to be my short-term fix:

require 'connection_pool'

module ActiveSupport
  module Cache
    class RedisStore < Store
      def initialize(*addresses)
        @data = ::ConnectionPool::Wrapper.new(size: 5, timeout: 5) { ::Redis::Store::Factory.create(addresses) }
        super(addresses.extract_options!)
      end
    end
  end
end
@findchris

This comment has been minimized.

findchris commented Oct 2, 2014

@mperham, can you offer any other suggestions for introducing a ConnectionPool into a library that constructs clients internally?

@mperham

This comment has been minimized.

mperham commented Oct 2, 2014

Not really without monkeypatching.

Dalli 2.7 supports connection_pools, here's the code if it gives you further ideas.

https://github.com/mperham/dalli#multithreading-and-rails
https://github.com/mperham/dalli/blob/master/lib/active_support/cache/dalli_store.rb#L52

@findchris

This comment has been minimized.

findchris commented Oct 2, 2014

Thanks @mperham for chiming in.

@jodosha, would you be interested in a pull request that would support connection pooling, similar to how dalli does it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment