// return the connection to the pool try { if (pool != null) { if (!broken) { // reset the connection if (dbIndex > 0) { select(0); } pool.returnResource(jedis); return; } } } catch (Exception ex) { // exceptions are handled below }
if (pool != null && broken) { pool.returnBrokenResource(jedis); return; }
// return the connection to the pool try { if (pool != null) { if (!broken) { // reset the connection if (dbIndex > 0) { select(0); } pool.returnResource(jedis); return; } } } catch (Exception ex) { // exceptions are handled below }
if (pool != null && broken) { pool.returnBrokenResource(jedis); return; }
引用来自“gzgz8080”的评论
github上已经有人发现这个问题,并且都fix了https://github.com/xetorthio/jedis/issues/186
引用来自“乒乓狂魔”的评论
是的,但是还有更多地方值得我们深思1 jedis为什么要暴漏这么个危险的API给用户使用(即要求用户自觉的close,不自觉后果自负),
而这种增加用户操作复杂度的API是可以避免的,所以在我们开发相关框架给别人使用的时候,尽量避免出现这种情况。
2 可以再想想出现这种问题的根本原因是什么,即同步通信中的请求响应不匹配的问题,
这种应该是很容易出现的,给我们的启示就是:在一开始设计的时候就要去考虑这一点,从而就可以避免造出这么一个大坑
引用来自“gzgz8080”的评论
其实我之前也想过,为什么jedis不像jdbc的auto-commit那样,调用一次后,自动将连接归还给连接池。后来在业务上,经常遇到一处业务逻辑里多次调用redis。
比如
Jedis jedis = pool.getResource();
jedis.get(...);
jedis.set(...);
jedis.zrange(...);
...
jedis.close();
如果jedis做得像jdbc那样的话,
每调用一次后都自动归还,下次调用时又再次申请连接的话,
系统开销比较大,而且代码也变得繁复。
引用来自“gzgz8080”的评论
github上已经有人发现这个问题,并且都fix了https://github.com/xetorthio/jedis/issues/186
引用来自“乒乓狂魔”的评论
是的,但是还有更多地方值得我们深思1 jedis为什么要暴漏这么个危险的API给用户使用(即要求用户自觉的close,不自觉后果自负),
而这种增加用户操作复杂度的API是可以避免的,所以在我们开发相关框架给别人使用的时候,尽量避免出现这种情况。
2 可以再想想出现这种问题的根本原因是什么,即同步通信中的请求响应不匹配的问题,
这种应该是很容易出现的,给我们的启示就是:在一开始设计的时候就要去考虑这一点,从而就可以避免造出这么一个大坑
后来在业务上,经常遇到一处业务逻辑里多次调用redis。
比如
Jedis jedis = pool.getResource();
jedis.get(...);
jedis.set(...);
jedis.zrange(...);
...
jedis.close();
如果jedis做得像jdbc那样的话,
每调用一次后都自动归还,下次调用时又再次申请连接的话,
系统开销比较大,而且代码也变得繁复。
引用来自“gzgz8080”的评论
github上已经有人发现这个问题,并且都fix了https://github.com/xetorthio/jedis/issues/186
引用来自“乒乓狂魔”的评论
是的,但是还有更多地方值得我们深思1 jedis为什么要暴漏这么个危险的API给用户使用(即要求用户自觉的close,不自觉后果自负),
而这种增加用户操作复杂度的API是可以避免的,所以在我们开发相关框架给别人使用的时候,尽量避免出现这种情况。
2 可以再想想出现这种问题的根本原因是什么,即同步通信中的请求响应不匹配的问题,
这种应该是很容易出现的,给我们的启示就是:在一开始设计的时候就要去考虑这一点,从而就可以避免造出这么一个大坑
引用来自“gzgz8080”的评论
github上已经有人发现这个问题,并且都fix了https://github.com/xetorthio/jedis/issues/186
1 jedis为什么要暴漏这么个危险的API给用户使用(即要求用户自觉的close,不自觉后果自负),
而这种增加用户操作复杂度的API是可以避免的,所以在我们开发相关框架给别人使用的时候,尽量避免出现这种情况。
2 可以再想想出现这种问题的根本原因是什么,即同步通信中的请求响应不匹配的问题,
这种应该是很容易出现的,给我们的启示就是:在一开始设计的时候就要去考虑这一点,从而就可以避免造出这么一个大坑
引用来自“65535”的评论
看了下,所以spring-data-redis 已经帮我们避免了这些类的问题。// return the connection to the pool
try {
if (pool != null) {
if (!broken) {
// reset the connection
if (dbIndex > 0) {
select(0);
}
pool.returnResource(jedis);
return;
}
}
} catch (Exception ex) {
// exceptions are handled below
}
if (pool != null && broken) {
pool.returnBrokenResource(jedis);
return;
}
// return the connection to the pool
try {
if (pool != null) {
if (!broken) {
// reset the connection
if (dbIndex > 0) {
select(0);
}
pool.returnResource(jedis);
return;
}
}
} catch (Exception ex) {
// exceptions are handled below
}
if (pool != null && broken) {
pool.returnBrokenResource(jedis);
return;
}