Browse Source

redis连接没有关闭的问题

master
richie 5 years ago
parent
commit
9b2c1b0dd5
  1. 3
      plugin.xml
  2. 7
      src/main/java/com/fr/plugin/db/redis/core/RedisDatabaseConnection.java
  3. 4
      src/main/java/com/fr/plugin/db/redis/core/RedisScriptTableDataModel.java
  4. 4
      src/main/java/com/fr/plugin/db/redis/core/RedisTableDataModel.java

3
plugin.xml

@ -3,12 +3,13 @@
<id>com.fr.solution.plugin.db.redis.v10</id> <id>com.fr.solution.plugin.db.redis.v10</id>
<name><![CDATA[Redis数据集]]></name> <name><![CDATA[Redis数据集]]></name>
<active>yes</active> <active>yes</active>
<version>7.3.2</version> <version>7.3.3</version>
<env-version>10.0</env-version> <env-version>10.0</env-version>
<jartime>2020-01-20</jartime> <jartime>2020-01-20</jartime>
<vendor>richie</vendor> <vendor>richie</vendor>
<description><![CDATA[可以连接Redis数据库,支持哈希表、列表、集合以及有序集合]]></description> <description><![CDATA[可以连接Redis数据库,支持哈希表、列表、集合以及有序集合]]></description>
<change-notes><![CDATA[ <change-notes><![CDATA[
[2020-06-09]修复redis连接没有正确关闭的问题。<br/>
[2020-06-05]搜索key的时候可以选择不同的数据库。<br> [2020-06-05]搜索key的时候可以选择不同的数据库。<br>
[2020-04-26]修复插件被标记为需要付费的问题。<br/> [2020-04-26]修复插件被标记为需要付费的问题。<br/>
[2020-04-21]修复redis集群下的一个问题。<br/> [2020-04-21]修复redis集群下的一个问题。<br/>

7
src/main/java/com/fr/plugin/db/redis/core/RedisDatabaseConnection.java

@ -80,17 +80,18 @@ public class RedisDatabaseConnection extends BaseConnection {
return ArrayKit.EMPTY_STRING_ARRAY; return ArrayKit.EMPTY_STRING_ARRAY;
} else { } else {
Redis redis = createRedisClient(); Redis redis = createRedisClient();
try {
EmbedRedis embedRedis = redis.getClient(); EmbedRedis embedRedis = redis.getClient();
int len = ArrayKit.getLength(args); int len = ArrayKit.getLength(args);
if (len > 1) { if (len > 1) {
int dbIndex = Integer.parseInt(args[1]); int dbIndex = Integer.parseInt(args[1]);
embedRedis.select(dbIndex); embedRedis.select(dbIndex);
} }
Set<String> keys = embedRedis.keys(args[0]); Set<String> keys = embedRedis.keys(args[0]);
String[] array = keys.toArray(new String[0]); return keys.toArray(new String[0]);
} finally {
redis.close(); redis.close();
return array; }
} }
} }

4
src/main/java/com/fr/plugin/db/redis/core/RedisScriptTableDataModel.java

@ -38,6 +38,7 @@ public class RedisScriptTableDataModel extends BaseDataModel {
return; return;
} }
Redis redis = mc.createRedisClient(); Redis redis = mc.createRedisClient();
try {
redis.getClient().select(dbIndex); redis.getClient().select(dbIndex);
RedisClient redisClient = RedisClientSelector.select(redis, engineType); RedisClient redisClient = RedisClientSelector.select(redis, engineType);
SimpleDataModel simple = redisClient.build(redis, script, rowCount); SimpleDataModel simple = redisClient.build(redis, script, rowCount);
@ -46,6 +47,9 @@ public class RedisScriptTableDataModel extends BaseDataModel {
this.data = simple.getData(); this.data = simple.getData();
this.rowCount = simple.getRowCount(); this.rowCount = simple.getRowCount();
} }
} finally {
redis.close();
}
} }

4
src/main/java/com/fr/plugin/db/redis/core/RedisTableDataModel.java

@ -28,9 +28,9 @@ public class RedisTableDataModel extends BaseDataModel {
return; return;
} }
Redis redis = mc.createRedisClient(); Redis redis = mc.createRedisClient();
try {
redis.getClient().select(dbIndex); redis.getClient().select(dbIndex);
LogKit.info("Connect to redis and select database:" + dbIndex); LogKit.info("Connect to redis and select database:" + dbIndex);
try {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
DataWrapper<Object> wrapper = VisitorFactory.getKeyValueResult(calculator, ps, redis.getClient(), query, rowCount); DataWrapper<Object> wrapper = VisitorFactory.getKeyValueResult(calculator, ps, redis.getClient(), query, rowCount);
LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start); LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start);
@ -40,6 +40,8 @@ public class RedisTableDataModel extends BaseDataModel {
redis.close(); redis.close();
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e.getCause()); throw new RuntimeException(e.getCause());
} finally {
redis.close();
} }
} }

Loading…
Cancel
Save