Browse Source

redis连接没有关闭的问题

master
richie 5 years ago
parent
commit
9b2c1b0dd5
  1. 3
      plugin.xml
  2. 21
      src/main/java/com/fr/plugin/db/redis/core/RedisDatabaseConnection.java
  3. 18
      src/main/java/com/fr/plugin/db/redis/core/RedisScriptTableDataModel.java
  4. 6
      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/>

21
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();
EmbedRedis embedRedis = redis.getClient(); try {
int len = ArrayKit.getLength(args); EmbedRedis embedRedis = redis.getClient();
if (len > 1) { int len = ArrayKit.getLength(args);
int dbIndex = Integer.parseInt(args[1]); if (len > 1) {
embedRedis.select(dbIndex); int dbIndex = Integer.parseInt(args[1]);
embedRedis.select(dbIndex);
}
Set<String> keys = embedRedis.keys(args[0]);
return keys.toArray(new String[0]);
} finally {
redis.close();
} }
Set<String> keys = embedRedis.keys(args[0]);
String[] array = keys.toArray(new String[0]);
redis.close();
return array;
} }
} }

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

@ -38,13 +38,17 @@ public class RedisScriptTableDataModel extends BaseDataModel {
return; return;
} }
Redis redis = mc.createRedisClient(); Redis redis = mc.createRedisClient();
redis.getClient().select(dbIndex); try {
RedisClient redisClient = RedisClientSelector.select(redis, engineType); redis.getClient().select(dbIndex);
SimpleDataModel simple = redisClient.build(redis, script, rowCount); RedisClient redisClient = RedisClientSelector.select(redis, engineType);
if (simple != null) { SimpleDataModel simple = redisClient.build(redis, script, rowCount);
this.columnNames = simple.getColumnNames(); if (simple != null) {
this.data = simple.getData(); this.columnNames = simple.getColumnNames();
this.rowCount = simple.getRowCount(); this.data = simple.getData();
this.rowCount = simple.getRowCount();
}
} finally {
redis.close();
} }
} }

6
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();
redis.getClient().select(dbIndex);
LogKit.info("Connect to redis and select database:" + dbIndex);
try { try {
redis.getClient().select(dbIndex);
LogKit.info("Connect to redis and select database:" + dbIndex);
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