From 9b2c1b0dd59d5da37088977f9d2dcf8afd3729b7 Mon Sep 17 00:00:00 2001 From: richie Date: Tue, 9 Jun 2020 14:10:02 +0800 Subject: [PATCH] =?UTF-8?q?redis=E8=BF=9E=E6=8E=A5=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin.xml | 3 ++- .../redis/core/RedisDatabaseConnection.java | 21 ++++++++++--------- .../redis/core/RedisScriptTableDataModel.java | 18 +++++++++------- .../db/redis/core/RedisTableDataModel.java | 6 ++++-- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/plugin.xml b/plugin.xml index de73740..2553bf6 100755 --- a/plugin.xml +++ b/plugin.xml @@ -3,12 +3,13 @@ com.fr.solution.plugin.db.redis.v10 yes - 7.3.2 + 7.3.3 10.0 2020-01-20 richie [2020-06-05]搜索key的时候可以选择不同的数据库。
[2020-04-26]修复插件被标记为需要付费的问题。
[2020-04-21]修复redis集群下的一个问题。
diff --git a/src/main/java/com/fr/plugin/db/redis/core/RedisDatabaseConnection.java b/src/main/java/com/fr/plugin/db/redis/core/RedisDatabaseConnection.java index b8b2eea..63e2c4e 100755 --- a/src/main/java/com/fr/plugin/db/redis/core/RedisDatabaseConnection.java +++ b/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 keys = embedRedis.keys(args[0]); + return keys.toArray(new String[0]); + } finally { + redis.close(); } - - Set keys = embedRedis.keys(args[0]); - String[] array = keys.toArray(new String[0]); - redis.close(); - return array; } } diff --git a/src/main/java/com/fr/plugin/db/redis/core/RedisScriptTableDataModel.java b/src/main/java/com/fr/plugin/db/redis/core/RedisScriptTableDataModel.java index 3ff402d..16d805f 100644 --- a/src/main/java/com/fr/plugin/db/redis/core/RedisScriptTableDataModel.java +++ b/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(); } } diff --git a/src/main/java/com/fr/plugin/db/redis/core/RedisTableDataModel.java b/src/main/java/com/fr/plugin/db/redis/core/RedisTableDataModel.java index 5bc5c40..19719e6 100644 --- a/src/main/java/com/fr/plugin/db/redis/core/RedisTableDataModel.java +++ b/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 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(); } }