-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
automaticall return Jedis instances to the pool when closed #44
Comments
I don't how we can make this possible. If we hide connection pooling within Jedis class, we will have to borrow a connection on every executed command and maybe even deal with synchronization issues. It will make things even harder. |
Or you could use an approach like this: |
Or use simple template/callback "pattern" just like jdbctemplate or hibernatetemplate. Something like:
And here is simple callback:
There is spring-data project which has redis support. I was going to use it and have played for a while but had to fall back to above solution as it is much simpler and spring-data is not mature at the moment. |
Maybe it make sense to put this in the Wiki or even in a Gist. If lots of people use we could add this to a contrib project, I don't know if I would add this to the core. |
Yeah, this is not for core. Just wrapper - and spring data sounds like ultimate solution. Maybe I will extract my wrapper classes and create spring-jedis or jedis-spring project someday :) |
I would love to see that. I'm using Spring and Jedis too. |
Oh, I see I need to drop it somewhere:
and here is xml:
and that's almost 90% in terms of LOC of whole "project". |
Well, In my case I'm using a ShardedJedisPool, this is with the apache pool, not the old version. I need to set up things like testWhileIdle or maxActive and it looks like I need to use an instance of org.apache.commons.pool.impl.GenericObjectPool.Config for that. This class doesn't have setters or getters so I had to extend it to provide setters so I could configure an instance and pass as a constructor-arg to my redis.clients.jedis.ShardedJedisPool. I was wondering if there was another way of doing it without extending the Config class. |
I would just pull code, fix it and kindly ask mr xetorthio to merge :) |
Even better it would be to simply depend only on the ObjectPool interface since one might want to use her own implementation or use the stack-based implementation. |
I am closing this issue since it seems we are talking about addind getters and setters to Config object instead of adding a Proxy class. |
Would it be possible to automatically return Jedis instances to the pool when they are 'closed' (disconnected/quit)? Currently one needs to keep track of the connection usage if JedisPool is used which makes it hard to properly do cleanup.
It's a lot easier and consistent to simply ask the client to work with a Jedis instance (no matter if JedisPool is used or not).
The text was updated successfully, but these errors were encountered: