Open mikebaldry opened 8 years ago
Are there other Redis libraries that use this pattern? I'm wondering if supporting https://github.com/mperham/connection_pool might be cleaner/easier.
@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) })
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
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.