Skip to content
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

Making it possible to use a connection pool for getting a Redis instance #21

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

mikebaldry
Copy link

In some (most production, I'd have thought) projects you have a pool of Redis connections from which you can checkout a connection, perform your actions then put it back in to the pool ready for the next thing to use.

This is not possible with your current implementation so I've added an option checkout_redis_with, you can pass in a lambda which yields with the Redis connection.

looks like

Ratelimit.new("abc", checkout_redis_with: -> (&block) { MyRedisPool.checkout(&block) })

or similar.

The original implementation still works the same, but checks out a connection when it needs to use one.

I've also updated it to use MULTI instead of pipelining as expressed in a previous unanswered PR.

…dis from a connection pool. Using MULTI instead of pipelining the requests, so they are atomic
@coveralls
Copy link

coveralls commented Sep 6, 2016

Coverage Status

Coverage increased (+0.1%) to 99.259% when pulling 7d1156f on Buyapowa:master into aa8bd7a on ejfinneran:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 99.259% when pulling 7d1156f on Buyapowa:master into aa8bd7a on ejfinneran:master.

@ejfinneran
Copy link
Owner

Are there other Redis libraries that use this pattern? I'm wondering if supporting https://github.com/mperham/connection_pool might be cleaner/easier.

@mikebaldry
Copy link
Author

mikebaldry commented Sep 26, 2016

@ejfinneran I did it in a specific way that allows that, you could do this:

redis_pool = ConnectionPool.new(size: 5, timeout: 5) { Redis::Client.new }

Ratelimit.new("blah", checkout_redis_with: &redis_pool.method(:with))

or as in the PR comment:

Ratelimit.new("blah", checkout_redis_with: -> (&block) { redis_pool.with(&block) })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants