stefanwille / crystal-redis

Full featured Redis client for Crystal
MIT License
380 stars 61 forks source link

integrate pool of connections with ysbaddaden/pool #60

Closed kostya closed 6 years ago

kostya commented 6 years ago

this is very needed in concurrent applications.

stefanwille commented 6 years ago

What type of integration do you have in mind? Connection pooling baked right in? Or would an example program do?

kostya commented 6 years ago

yes just baked in.

kostya commented 6 years ago

almost every concurrent/web applications need to add wrapper like this https://github.com/mperham/sidekiq.cr/blob/master/src/sidekiq/pool.cr#L55, why not add it inside.

stefanwille commented 6 years ago

So I guess the idea is to add a class Redis::Pool, where one can do this:

pool = Redis::Pool.new(host: ..., port: ..., pool_size: 250)
pool.redis do |conn|
     conn.set("mike", "rules") => "OK"
     conn.get("mike") => "rules"
end
kostya commented 6 years ago

if code have 100~ redis calls it problem to wrap every call with pool.redis (too much noise)

stefanwille commented 6 years ago

How would such a program checkout/checkin a connection? Explicitly, like so?

conn = pool.checkout
...
pool.checkin(conn)
kostya commented 6 years ago

not really imagine where and this can be used. for subscription only, but it can be hardcoded. all other command just always checkin.

stefanwille commented 6 years ago

Sorry, I don't understand what you mean?

stefanwille commented 6 years ago

This is the API you had in mind?

https://github.com/stefanwille/crystal-redis/pull/61/files