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

Already on GitHub? Sign in to your account

Share Redis connection between middleware and app? #146

Closed
steveh opened this Issue Aug 9, 2012 · 2 comments

Comments

Projects
None yet
3 participants

steveh commented Aug 9, 2012

Currently, my code looks something like this:

$redis_options = { :host => "..." }

Rails.application.config.session_store(:redis_store, {
  :namespace => "sessions",
  :servers => $redis_options.merge(:namespace => "sessions")
})

$redis = Redis.new($redis_options)

Can I either provide an existing Redis instance to session store, or extract the Redis instance out of the middleware to use in my app, to avoid creating 2 connections?

Contributor

mhoran commented Aug 9, 2012

Not currently. Although you could grab the #pool off of Rack::Session::Redis, its interface is that provided by redis-store, which is a wrapped Redis object with some methods which behave a bit differently from the upstream Redis API. It's probably best not to fumble with this object. It would, for example, add the namespace to all your keys.

There's no way to currently get at the raw Redis object, or pass one into the factory. However, this would be a great refactor, and we'd gladly take a pull request with tests.

steveh commented Aug 9, 2012

Cool. I'll see what I can come up with when I find the time. Just thought I'd better check if this wasn't already supported

@jodosha jodosha closed this Jan 18, 2013

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