Zoz
unread,Dec 8, 2010, 3:53:57 PM12/8/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Jedis
I wanted my client to be able to recover from redis server closed
connections, network problems, and redis server resets easily. To
have my client auto recover I used "tedpennings" JedisProxy idea to
wrap the calls to Jedis in a proxy that handles the exception stuff.
This is working pretty well.
But one problem I am having is that to use a proxy you need an
interface and the JedisCommands interface is missing some commands
like BLPOP, MULTI, PIPELINED, INFO etc.
On a more general note, we might want to think how this issue should
be handled in general. What I am doing is a hack, but I don't see a
better way. I think most people using Jedis from a web server
environment will want to do something like this or perform exception
handling and retry logic on every call to jedis (yuk).
The basic idea of the proxy is if a jedis command fails on a pooled
jedis connection then call returnBrokenResource, get a new jedis from
pool, and try the command again.
Proxy code snipit:
@Override
public Object invoke(Object proxy, Method m, Object[] args) throws
Throwable {
Object result = null;
int MAX_BROKEN_POOL_RESOURCES = 100;
int i = 0;
boolean success = false;
while (i < MAX_BROKEN_POOL_RESOURCES && !success) {
i++;
try {
result = m.invoke(jedis, args);
success = true;
} catch (InvocationTargetException e) {
Logger.info("Jedis Pool Problem: attempt: " + i + " "
+ e.getTargetException().getMessage());
jedisPool.returnBrokenResource(jedis);
jedis = obtainJedis(); // calls
jedisPool.getResource();
}
}
if (!success) {
Logger.error("RedisSession, unable to get resource from
pool.");
throw new Exception("RedisSession, unable to get resource
from pool.");
}
return result;
}