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>
<name><![CDATA[Redis数据集]]></name>
<active>yes</active>
<version>7.3.2</version>
<version>7.3.3</version>
<env-version>10.0</env-version>
<jartime>2020-01-20</jartime>
<vendor>richie</vendor>
<description><![CDATA[可以连接Redis数据库,支持哈希表、列表、集合以及有序集合]]></description>
<change-notes><![CDATA[
[2020-06-09]修复redis连接没有正确关闭的问题。<br/>
[2020-06-05]搜索key的时候可以选择不同的数据库。<br>
[2020-04-26]修复插件被标记为需要付费的问题。<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;
} else {
Redis redis = createRedisClient();
EmbedRedis embedRedis = redis.getClient();
int len = ArrayKit.getLength(args);
if (len > 1) {
int dbIndex = Integer.parseInt(args[1]);
embedRedis.select(dbIndex);
try {
EmbedRedis embedRedis = redis.getClient();
int len = ArrayKit.getLength(args);
if (len > 1) {
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;
}
Redis redis = mc.createRedisClient();
redis.getClient().select(dbIndex);
RedisClient redisClient = RedisClientSelector.select(redis, engineType);
SimpleDataModel simple = redisClient.build(redis, script, rowCount);
if (simple != null) {
this.columnNames = simple.getColumnNames();
this.data = simple.getData();
this.rowCount = simple.getRowCount();
try {
redis.getClient().select(dbIndex);
RedisClient redisClient = RedisClientSelector.select(redis, engineType);
SimpleDataModel simple = redisClient.build(redis, script, rowCount);
if (simple != null) {
this.columnNames = simple.getColumnNames();
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;
}
Redis redis = mc.createRedisClient();
redis.getClient().select(dbIndex);
LogKit.info("Connect to redis and select database:" + dbIndex);
try {
redis.getClient().select(dbIndex);
LogKit.info("Connect to redis and select database:" + dbIndex);
long start = System.currentTimeMillis();
DataWrapper<Object> wrapper = VisitorFactory.getKeyValueResult(calculator, ps, redis.getClient(), query, rowCount);
LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start);
@ -40,6 +40,8 @@ public class RedisTableDataModel extends BaseDataModel {
redis.close();
} catch (Exception e) {
throw new RuntimeException(e.getCause());
} finally {
redis.close();
}
}

Loading…
Cancel
Save