From 6e911d6a44833123f4269de0a5d4cd96161e074a Mon Sep 17 00:00:00 2001 From: richie Date: Wed, 18 Sep 2019 11:23:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=BF=9E=E6=8E=A5redis?= =?UTF-8?q?=E9=9B=86=E7=BE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin.xml | 5 +- .../redis/core/RedisDatabaseConnection.java | 12 +- .../fr/plugin/db/redis/core/RedisPool.java | 87 +++++++++++-- .../db/redis/core/accessor/EmbedRedis.java | 40 ++++++ .../accessor/category/ClusterRedisClient.java | 118 ++++++++++++++++++ .../category/StandaloneRedisClient.java | 89 +++++++++++++ .../fr/plugin/db/redis/core/emb/Redis.java | 4 +- .../db/redis/core/emb/impl/ProxyRedis.java | 21 ++-- .../db/redis/core/emb/impl/SimpleRedis.java | 21 ++-- .../db/redis/core/visit/AbstractVisitor.java | 4 +- .../plugin/db/redis/core/visit/Visitor.java | 6 +- .../db/redis/core/visit/VisitorFactory.java | 3 +- .../db/redis/core/visit/impl/GetVisitor.java | 6 +- .../redis/core/visit/impl/HashGetVisitor.java | 4 +- .../core/visit/impl/HashKeysVisitor.java | 4 +- .../core/visit/impl/HashMGetVisitor.java | 4 +- .../db/redis/core/visit/impl/HashVisitor.java | 4 +- .../db/redis/core/visit/impl/KeysVisitor.java | 4 +- .../db/redis/core/visit/impl/ListVisitor.java | 4 +- .../db/redis/core/visit/impl/MGetVisitor.java | 4 +- .../db/redis/core/visit/impl/SetVisitor.java | 4 +- .../redis/core/visit/impl/ZRangeVisitor.java | 4 +- .../db/redis/help/client/BaseRedisClient.java | 5 +- .../redis/help/client/RedisNashornClient.java | 4 +- .../db/redis/help/client/RedisV8Client.java | 10 +- .../db/redis/ui/RedisConnectionPane.java | 25 ++-- .../plugin/db/redis/locale/redis.properties | 3 +- .../db/redis/locale/redis_en_US.properties | 3 +- .../db/redis/locale/redis_zh_CN.properties | 5 +- 29 files changed, 427 insertions(+), 80 deletions(-) create mode 100644 src/main/java/com/fr/plugin/db/redis/core/accessor/EmbedRedis.java create mode 100644 src/main/java/com/fr/plugin/db/redis/core/accessor/category/ClusterRedisClient.java create mode 100644 src/main/java/com/fr/plugin/db/redis/core/accessor/category/StandaloneRedisClient.java diff --git a/plugin.xml b/plugin.xml index abca42d..8d09dbf 100755 --- a/plugin.xml +++ b/plugin.xml @@ -3,12 +3,13 @@ com.fr.solution.plugin.db.redis.v10 yes - 6.2 + 7.0 10.0 - 2018-11-29 + 2019-07-29 richie [2019-08-26]给console增加一个engine()函数,判断使用的脚本引擎名字。
[2019-08-26]不支持V8引擎的机器上使用JDK内置的脚本引擎(仅支持ES5语法)。
[2019-03-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 8d9ff85..a78ac3e 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 @@ -21,7 +21,7 @@ public class RedisDatabaseConnection extends BaseConnection { private static final int DEFAULT_REDIS_PORT = 6379; private Conf host = HolderKit.simple(StringKit.EMPTY); - private Conf port = HolderKit.simple(DEFAULT_REDIS_PORT); + private Conf port = HolderKit.simple(String.valueOf(DEFAULT_REDIS_PORT)); private Conf password = HolderKit.simple(StringKit.EMPTY); public RedisDatabaseConnection() { @@ -36,11 +36,11 @@ public class RedisDatabaseConnection extends BaseConnection { this.host.set(host); } - public int getPort() { + public String getPort() { return port.get(); } - public void setPort(int port) { + public void setPort(String port) { this.port.set(port); } @@ -68,7 +68,7 @@ public class RedisDatabaseConnection extends BaseConnection { } public Redis createRedisClient() { - return RedisPool.getPool().getResource(getHost(), getPort(), getPassword()); + return RedisPool.getFinal(getHost(), getPort(), getPassword()); } @Override @@ -135,7 +135,7 @@ public class RedisDatabaseConnection extends BaseConnection { String tagName = reader.getTagName(); if ("Attr".equals(tagName)) { setHost(reader.getAttrAsString("host", StringKit.EMPTY)); - setPort(reader.getAttrAsInt("port", DEFAULT_REDIS_PORT)); + setPort(reader.getAttrAsString("port", String.valueOf(DEFAULT_REDIS_PORT))); String pwd = reader.getAttrAsString("password", StringKit.EMPTY); if (StringKit.isNotEmpty(pwd)) { setPassword(SecurityKit.encrypt(pwd)); @@ -160,7 +160,7 @@ public class RedisDatabaseConnection extends BaseConnection { public Object clone() throws CloneNotSupportedException { com.fr.plugin.db.redis.core.RedisDatabaseConnection cloned = (com.fr.plugin.db.redis.core.RedisDatabaseConnection) super.clone(); cloned.host = (Conf) host.clone(); - cloned.port = (Conf) port.clone(); + cloned.port = (Conf) port.clone(); cloned.password = (Conf) password.clone(); return cloned; } diff --git a/src/main/java/com/fr/plugin/db/redis/core/RedisPool.java b/src/main/java/com/fr/plugin/db/redis/core/RedisPool.java index 1403111..b7aa12a 100644 --- a/src/main/java/com/fr/plugin/db/redis/core/RedisPool.java +++ b/src/main/java/com/fr/plugin/db/redis/core/RedisPool.java @@ -4,21 +4,32 @@ import com.fanruan.api.conf.ConfigurationKit; import com.fanruan.api.generic.Matcher; import com.fanruan.api.generic.Runner; import com.fanruan.api.log.LogKit; +import com.fanruan.api.util.ArrayKit; import com.fanruan.api.util.StringKit; import com.fr.config.Configuration; +import com.fr.plugin.db.redis.core.accessor.category.ClusterRedisClient; +import com.fr.plugin.db.redis.core.accessor.category.StandaloneRedisClient; import com.fr.plugin.db.redis.core.emb.Redis; import com.fr.plugin.db.redis.core.emb.impl.ProxyRedis; import com.fr.plugin.db.redis.core.emb.impl.SimpleRedis; import com.fr.plugin.db.redis.core.pool.RedisConnectionPoolConfig; import com.fr.plugin.db.redis.core.pool.RedisConnectionProxyConfig; +import com.fr.stable.collections.combination.Pair; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; +import org.apache.commons.pool2.impl.GenericObjectPoolConfig; +import redis.clients.jedis.HostAndPort; import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisCluster; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; /** @@ -44,17 +55,27 @@ public class RedisPool { }); } - public static RedisPool getPool() { - return pool; - } - private Map jedisPoolMap = new ConcurrentHashMap(); private void clearAll() { jedisPoolMap.clear(); } - public Redis getResource(String host, int port, String password) { + public static Redis getFinal(String host, String port, String password) { + List> pairs = findAllHostAndPassword(host, port); + if (pairs.size() == 1) { + return pool.getStandaloneResource(pairs.get(0), password); + } else { + return pool.getJedisCluster(pairs, password); + } + } + + + public Redis getStandaloneResource(Pair hostAndPort, String password) { + + String host = hostAndPort.getFirst(); + int port = hostAndPort.getSecond(); + if (RedisConnectionProxyConfig.getInstance().isOpen()) { try { return createJedisBySSH(host, port, password); @@ -68,14 +89,14 @@ public class RedisPool { jedisPool = createJedisPool(host, port, password); jedisPoolMap.put(feature, jedisPool); } - return new SimpleRedis(jedisPool.getResource()); + return new SimpleRedis(new StandaloneRedisClient(jedisPool.getResource())); } Jedis jedis = new Jedis(host, port); jedis.auth(password); - return new SimpleRedis(jedis); + return new SimpleRedis(new StandaloneRedisClient(jedis)); } - private JedisPool createJedisPool(String host, int port, String password) { + private static JedisPool createJedisPool(String host, int port, String password) { RedisConnectionPoolConfig poolConfig = RedisConnectionPoolConfig.getInstance(); JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(poolConfig.getMaxTotal()); @@ -133,7 +154,55 @@ public class RedisPool { if (StringKit.isNotBlank(password)) { jedis.auth(password); } - return new ProxyRedis(session, jedis); + return new ProxyRedis(session, new StandaloneRedisClient(jedis)); + } + + private Redis getJedisCluster(List> hostAndPorts, String password) { + RedisConnectionPoolConfig poolConfig = RedisConnectionPoolConfig.getInstance(); + GenericObjectPoolConfig config = new GenericObjectPoolConfig(); + + config.setMaxTotal(poolConfig.getMaxTotal()); + //控制一个pool最多有多少个状态为idle(空闲的)的jedis实例。 + + //是否启用后进先出, 默认true + config.setLifo(poolConfig.getLifo()); + + config.setMinIdle(1); + config.setMaxIdle(poolConfig.getMaxIdle()); + //表示当borrow(引入)一个jedis实例时,最大的等待时间,如果超过等待时间,则直接抛出JedisConnectionException; + config.setMaxWaitMillis(poolConfig.getMaxWait()); + config.setTimeBetweenEvictionRunsMillis(-1); + // 在borrow一个jedis实例时,是否提前进行alidate操作;如果为true,则得到的jedis实例均是可用的; + config.setTestOnBorrow(true); + // 在还会给pool时,是否提前进行validate操作 + config.setTestOnReturn(true); + //如果为true,表示有一个idle object evitor线程对idle object进行扫描,如果validate失败,此object会被从pool中drop掉;这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义; + config.setTestWhileIdle(true); + //表示一个对象至少停留在idle状态的最短时间,然后才能被idle object evitor扫描并驱逐;这一项只有在timeBetweenEvictionRunsMillis大于0时才有意义; + config.setMinEvictableIdleTimeMillis(6000); + //表示idle object evitor两次扫描之间要sleep的毫秒数 + config.setTimeBetweenEvictionRunsMillis(30000); + Set nodes = new LinkedHashSet(); + for (Pair pair : hostAndPorts) { + nodes.add(new HostAndPort(pair.getFirst(), pair.getSecond())); + } + JedisCluster jedisCluster; + if (StringKit.isNotEmpty(password)) { + jedisCluster = new JedisCluster(nodes, poolConfig.getTimeout(), 10000, 5, password, config); + } else { + jedisCluster = new JedisCluster(nodes, poolConfig.getTimeout(), 10000, 5, config); + } + return new SimpleRedis(new ClusterRedisClient(jedisCluster)); + } + private static List> findAllHostAndPassword(String host, String port) { + String[] hostArray = host.split(","); + String[] portArray = port.split(","); + int len = ArrayKit.getLength(hostArray); + List> pairs = new ArrayList>(); + for (int i = 0; i < len; i++) { + pairs.add(new Pair(hostArray[i], Integer.parseInt(portArray[i]))); + } + return pairs; } } diff --git a/src/main/java/com/fr/plugin/db/redis/core/accessor/EmbedRedis.java b/src/main/java/com/fr/plugin/db/redis/core/accessor/EmbedRedis.java new file mode 100644 index 0000000..3d64755 --- /dev/null +++ b/src/main/java/com/fr/plugin/db/redis/core/accessor/EmbedRedis.java @@ -0,0 +1,40 @@ +package com.fr.plugin.db.redis.core.accessor; + +import redis.clients.jedis.Tuple; + +import java.io.Closeable; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-09-18 + */ +public interface EmbedRedis extends Closeable { + + Set keys(String pattern); + + String get(String key); + + String hget(String key, String field); + + List hmget(String key, String... fields); + + Map hgetAll(String key); + + Set hkeys(String key); + + List lrange(String key, long start, long end); + + List mget(String... keys); + + Set smembers(String key); + + Set zrangeWithScores(final String key, final long start, final long end); + + void select(int index); + + String ping(); +} diff --git a/src/main/java/com/fr/plugin/db/redis/core/accessor/category/ClusterRedisClient.java b/src/main/java/com/fr/plugin/db/redis/core/accessor/category/ClusterRedisClient.java new file mode 100644 index 0000000..69d3124 --- /dev/null +++ b/src/main/java/com/fr/plugin/db/redis/core/accessor/category/ClusterRedisClient.java @@ -0,0 +1,118 @@ +package com.fr.plugin.db.redis.core.accessor.category; + +import com.fanruan.api.log.LogKit; +import com.fr.plugin.db.redis.core.accessor.EmbedRedis; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisCluster; +import redis.clients.jedis.JedisPool; +import redis.clients.jedis.Tuple; + +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-09-18 + */ +public class ClusterRedisClient implements EmbedRedis { + + private JedisCluster jedisCluster; + + public ClusterRedisClient(JedisCluster jedisCluster) { + this.jedisCluster = jedisCluster; + } + + @Override + public Set keys(String pattern) { + TreeSet keys = new TreeSet(); + Map clusterNodes = jedisCluster.getClusterNodes(); + for (String k : clusterNodes.keySet()) { + JedisPool jp = clusterNodes.get(k); + Jedis connection = jp.getResource(); + try { + keys.addAll(connection.keys(pattern)); + } catch (Exception e) { + LogKit.error(e.getMessage(), e); + } finally { + connection.close(); + } + } + return keys; + } + + @Override + public String get(String key) { + return jedisCluster.get(key); + } + + @Override + public String hget(String key, String field) { + return jedisCluster.hget(key, field); + } + + @Override + public List hmget(String key, String... fields) { + return jedisCluster.hmget(key, fields); + } + + @Override + public Map hgetAll(String key) { + return jedisCluster.hgetAll(key); + } + + @Override + public Set hkeys(String key) { + return jedisCluster.hkeys(key); + } + + @Override + public List lrange(String key, long start, long end) { + return jedisCluster.lrange(key, start, end); + } + + @Override + public List mget(String... keys) { + return jedisCluster.mget(keys); + } + + @Override + public Set smembers(String key) { + return jedisCluster.smembers(key); + } + + @Override + public Set zrangeWithScores(String key, long start, long end) { + return jedisCluster.zrangeWithScores(key, start, end); + } + + @Override + public void select(int index) { + jedisCluster.select(index); + } + + @Override + public String ping() { + Map clusterNodes = jedisCluster.getClusterNodes(); + for (String k : clusterNodes.keySet()) { + JedisPool jp = clusterNodes.get(k); + Jedis connection = jp.getResource(); + try { + return connection.ping(); + } catch (Exception e) { + LogKit.error(e.getMessage(), e); + } finally { + connection.close(); + } + } + return null; + } + + @Override + public void close() throws IOException { + jedisCluster.close(); + } +} diff --git a/src/main/java/com/fr/plugin/db/redis/core/accessor/category/StandaloneRedisClient.java b/src/main/java/com/fr/plugin/db/redis/core/accessor/category/StandaloneRedisClient.java new file mode 100644 index 0000000..2d60f0b --- /dev/null +++ b/src/main/java/com/fr/plugin/db/redis/core/accessor/category/StandaloneRedisClient.java @@ -0,0 +1,89 @@ +package com.fr.plugin.db.redis.core.accessor.category; + +import com.fr.plugin.db.redis.core.accessor.EmbedRedis; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.Tuple; + +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-09-18 + */ +public class StandaloneRedisClient implements EmbedRedis { + + private Jedis jedis; + + public StandaloneRedisClient(Jedis jedis) { + this.jedis = jedis; + } + + @Override + public Set keys(String pattern) { + return jedis.keys(pattern); + } + + @Override + public String get(String key) { + return jedis.get(key); + } + + @Override + public String hget(String key, String field) { + return jedis.hget(key, field); + } + + @Override + public List hmget(String key, String... fields) { + return jedis.hmget(key, fields); + } + + @Override + public Map hgetAll(String key) { + return jedis.hgetAll(key); + } + + @Override + public Set hkeys(String key) { + return jedis.hkeys(key); + } + + @Override + public List lrange(String key, long start, long end) { + return jedis.lrange(key, start, end); + } + + @Override + public List mget(String... keys) { + return jedis.mget(keys); + } + + @Override + public Set smembers(String key) { + return jedis.smembers(key); + } + + @Override + public Set zrangeWithScores(String key, long start, long end) { + return jedis.zrangeWithScores(key, start, end); + } + + @Override + public void select(int index) { + jedis.select(index); + } + + @Override + public String ping() { + return jedis.ping(); + } + + @Override + public void close() throws IOException { + jedis.close(); + } +} diff --git a/src/main/java/com/fr/plugin/db/redis/core/emb/Redis.java b/src/main/java/com/fr/plugin/db/redis/core/emb/Redis.java index 3547dde..ef483a7 100644 --- a/src/main/java/com/fr/plugin/db/redis/core/emb/Redis.java +++ b/src/main/java/com/fr/plugin/db/redis/core/emb/Redis.java @@ -1,6 +1,6 @@ package com.fr.plugin.db.redis.core.emb; -import redis.clients.jedis.Jedis; +import com.fr.plugin.db.redis.core.accessor.EmbedRedis; /** * @author richie @@ -9,7 +9,7 @@ import redis.clients.jedis.Jedis; */ public interface Redis { - Jedis getClient(); + EmbedRedis getClient(); void close(); } diff --git a/src/main/java/com/fr/plugin/db/redis/core/emb/impl/ProxyRedis.java b/src/main/java/com/fr/plugin/db/redis/core/emb/impl/ProxyRedis.java index 80f8ddc..be9ecc5 100644 --- a/src/main/java/com/fr/plugin/db/redis/core/emb/impl/ProxyRedis.java +++ b/src/main/java/com/fr/plugin/db/redis/core/emb/impl/ProxyRedis.java @@ -1,9 +1,12 @@ package com.fr.plugin.db.redis.core.emb.impl; +import com.fanruan.api.log.LogKit; +import com.fr.plugin.db.redis.core.accessor.EmbedRedis; import com.fr.plugin.db.redis.core.emb.Redis; -import redis.clients.jedis.Jedis; import com.jcraft.jsch.Session; +import java.io.IOException; + /** * @author richie * @version 10.0 @@ -12,21 +15,25 @@ import com.jcraft.jsch.Session; public class ProxyRedis implements Redis { private Session session; - private Jedis jedis; + private EmbedRedis redis; - public ProxyRedis(Session session, Jedis jedis) { + public ProxyRedis(Session session, EmbedRedis redis) { this.session = session; - this.jedis = jedis; + this.redis = redis; } @Override - public Jedis getClient() { - return jedis; + public EmbedRedis getClient() { + return redis; } @Override public void close() { - jedis.close(); + try { + redis.close(); + } catch (IOException e) { + LogKit.error(e.getMessage(), e); + } session.disconnect(); } } diff --git a/src/main/java/com/fr/plugin/db/redis/core/emb/impl/SimpleRedis.java b/src/main/java/com/fr/plugin/db/redis/core/emb/impl/SimpleRedis.java index 7d03fc1..b7d2eca 100644 --- a/src/main/java/com/fr/plugin/db/redis/core/emb/impl/SimpleRedis.java +++ b/src/main/java/com/fr/plugin/db/redis/core/emb/impl/SimpleRedis.java @@ -1,7 +1,10 @@ package com.fr.plugin.db.redis.core.emb.impl; +import com.fanruan.api.log.LogKit; +import com.fr.plugin.db.redis.core.accessor.EmbedRedis; import com.fr.plugin.db.redis.core.emb.Redis; -import redis.clients.jedis.Jedis; + +import java.io.IOException; /** * @author richie @@ -10,19 +13,23 @@ import redis.clients.jedis.Jedis; */ public class SimpleRedis implements Redis { - private Jedis jedis; + private EmbedRedis redis; - public SimpleRedis(Jedis jedis) { - this.jedis = jedis; + public SimpleRedis(EmbedRedis redis) { + this.redis = redis; } @Override - public Jedis getClient() { - return jedis; + public EmbedRedis getClient() { + return redis; } @Override public void close() { - jedis.close(); + try { + redis.close(); + } catch (IOException e) { + LogKit.error(e.getMessage(), e); + } } } diff --git a/src/main/java/com/fr/plugin/db/redis/core/visit/AbstractVisitor.java b/src/main/java/com/fr/plugin/db/redis/core/visit/AbstractVisitor.java index 94e7bda..a19d59c 100644 --- a/src/main/java/com/fr/plugin/db/redis/core/visit/AbstractVisitor.java +++ b/src/main/java/com/fr/plugin/db/redis/core/visit/AbstractVisitor.java @@ -3,9 +3,9 @@ package com.fr.plugin.db.redis.core.visit; import com.fanruan.api.util.StringKit; import com.fr.plugin.db.redis.core.DataWrapper; import com.fr.plugin.db.redis.core.RedisConstants; +import com.fr.plugin.db.redis.core.accessor.EmbedRedis; import com.fr.stable.ParameterProvider; import com.fr.stable.script.CalculatorProvider; -import redis.clients.jedis.Jedis; /** * Created by richie on 2017/5/2. @@ -13,7 +13,7 @@ import redis.clients.jedis.Jedis; public abstract class AbstractVisitor implements Visitor { @Override - public DataWrapper buildData(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception { + public DataWrapper buildData(CalculatorProvider calculator, ParameterProvider[] ps, EmbedRedis client, String query, int rowCount) throws Exception { return DataWrapper.create(getContent(calculator, ps, client, query, rowCount), RedisConstants.DEFAULT_COLUMN_NAMES); } diff --git a/src/main/java/com/fr/plugin/db/redis/core/visit/Visitor.java b/src/main/java/com/fr/plugin/db/redis/core/visit/Visitor.java index 2c81f16..c3ee830 100644 --- a/src/main/java/com/fr/plugin/db/redis/core/visit/Visitor.java +++ b/src/main/java/com/fr/plugin/db/redis/core/visit/Visitor.java @@ -1,9 +1,9 @@ package com.fr.plugin.db.redis.core.visit; import com.fr.plugin.db.redis.core.DataWrapper; +import com.fr.plugin.db.redis.core.accessor.EmbedRedis; import com.fr.stable.ParameterProvider; import com.fr.stable.script.CalculatorProvider; -import redis.clients.jedis.Jedis; import java.util.List; @@ -14,9 +14,9 @@ public interface Visitor { String TOKEN_SPACE = "\\s+"; - List> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception; + List> getContent(CalculatorProvider calculator, ParameterProvider[] ps, EmbedRedis client, String query, int rowCount) throws Exception; - DataWrapper buildData(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception; + DataWrapper buildData(CalculatorProvider calculator, ParameterProvider[] ps, EmbedRedis client, String query, int rowCount) throws Exception; boolean match(String query); diff --git a/src/main/java/com/fr/plugin/db/redis/core/visit/VisitorFactory.java b/src/main/java/com/fr/plugin/db/redis/core/visit/VisitorFactory.java index 966a18a..ab5cc2f 100644 --- a/src/main/java/com/fr/plugin/db/redis/core/visit/VisitorFactory.java +++ b/src/main/java/com/fr/plugin/db/redis/core/visit/VisitorFactory.java @@ -1,6 +1,7 @@ package com.fr.plugin.db.redis.core.visit; import com.fr.plugin.db.redis.core.DataWrapper; +import com.fr.plugin.db.redis.core.accessor.EmbedRedis; import com.fr.plugin.db.redis.core.visit.impl.GetVisitor; import com.fr.plugin.db.redis.core.visit.impl.HashGetVisitor; import com.fr.plugin.db.redis.core.visit.impl.HashKeysVisitor; @@ -38,7 +39,7 @@ public class VisitorFactory { visitors.add(new KeysVisitor()); } - public static DataWrapper getKeyValueResult(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception { + public static DataWrapper getKeyValueResult(CalculatorProvider calculator, ParameterProvider[] ps, EmbedRedis client, String query, int rowCount) throws Exception { Visitor visitor = getMatchedVisitor(query); if (visitor == null) { return DataWrapper.EMPTY; diff --git a/src/main/java/com/fr/plugin/db/redis/core/visit/impl/GetVisitor.java b/src/main/java/com/fr/plugin/db/redis/core/visit/impl/GetVisitor.java index 610551a..784c024 100644 --- a/src/main/java/com/fr/plugin/db/redis/core/visit/impl/GetVisitor.java +++ b/src/main/java/com/fr/plugin/db/redis/core/visit/impl/GetVisitor.java @@ -1,16 +1,16 @@ package com.fr.plugin.db.redis.core.visit.impl; +import com.fr.plugin.db.redis.core.accessor.EmbedRedis; import com.fr.plugin.db.redis.core.visit.AbstractVisitor; import com.fr.stable.ParameterProvider; import com.fr.stable.script.CalculatorProvider; -import redis.clients.jedis.Jedis; import java.util.ArrayList; import java.util.List; -public class GetVisitor extends AbstractVisitor { +public class GetVisitor extends AbstractVisitor { @Override - public List> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception { + public List> getContent(CalculatorProvider calculator, ParameterProvider[] ps, EmbedRedis client, String query, int rowCount) throws Exception { String[] arr = query.trim().split(TOKEN_SPACE); if (arr.length < 2) { throw new IllegalArgumentException("Illegal query:" + query); diff --git a/src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashGetVisitor.java b/src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashGetVisitor.java index 2975b48..a697f77 100644 --- a/src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashGetVisitor.java +++ b/src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashGetVisitor.java @@ -1,16 +1,16 @@ package com.fr.plugin.db.redis.core.visit.impl; +import com.fr.plugin.db.redis.core.accessor.EmbedRedis; import com.fr.plugin.db.redis.core.visit.AbstractVisitor; import com.fr.stable.ParameterProvider; import com.fr.stable.script.CalculatorProvider; -import redis.clients.jedis.Jedis; import java.util.ArrayList; import java.util.List; public class HashGetVisitor extends AbstractVisitor { @Override - public List> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception { + public List> getContent(CalculatorProvider calculator, ParameterProvider[] ps, EmbedRedis client, String query, int rowCount) throws Exception { String[] arr = query.trim().split(TOKEN_SPACE); if (arr.length < 3) { throw new IllegalArgumentException("Illegal query:" + query); diff --git a/src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashKeysVisitor.java b/src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashKeysVisitor.java index 66a693e..fc9255e 100644 --- a/src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashKeysVisitor.java +++ b/src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashKeysVisitor.java @@ -1,9 +1,9 @@ package com.fr.plugin.db.redis.core.visit.impl; +import com.fr.plugin.db.redis.core.accessor.EmbedRedis; import com.fr.plugin.db.redis.core.visit.AbstractVisitor; import com.fr.stable.ParameterProvider; import com.fr.stable.script.CalculatorProvider; -import redis.clients.jedis.Jedis; import java.util.ArrayList; import java.util.List; @@ -11,7 +11,7 @@ import java.util.Set; public class HashKeysVisitor extends AbstractVisitor { @Override - public List> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception { + public List> getContent(CalculatorProvider calculator, ParameterProvider[] ps, EmbedRedis client, String query, int rowCount) throws Exception { String[] arr = query.trim().split(TOKEN_SPACE); if (arr.length < 2) { throw new IllegalArgumentException("Illegal query:" + query); diff --git a/src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashMGetVisitor.java b/src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashMGetVisitor.java index b17c543..d287327 100644 --- a/src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashMGetVisitor.java +++ b/src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashMGetVisitor.java @@ -1,16 +1,16 @@ package com.fr.plugin.db.redis.core.visit.impl; +import com.fr.plugin.db.redis.core.accessor.EmbedRedis; import com.fr.plugin.db.redis.core.visit.AbstractVisitor; import com.fr.stable.ParameterProvider; import com.fr.stable.script.CalculatorProvider; -import redis.clients.jedis.Jedis; import java.util.ArrayList; import java.util.List; public class HashMGetVisitor extends AbstractVisitor{ @Override - public List> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception { + public List> getContent(CalculatorProvider calculator, ParameterProvider[] ps, EmbedRedis client, String query, int rowCount) throws Exception { String[] arr = query.trim().split(TOKEN_SPACE); if (arr.length < 3) { throw new IllegalArgumentException("Illegal query:" + query); diff --git a/src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashVisitor.java b/src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashVisitor.java index 62d84fe..dd96a6e 100644 --- a/src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashVisitor.java +++ b/src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashVisitor.java @@ -1,9 +1,9 @@ package com.fr.plugin.db.redis.core.visit.impl; +import com.fr.plugin.db.redis.core.accessor.EmbedRedis; import com.fr.plugin.db.redis.core.visit.AbstractVisitor; import com.fr.stable.ParameterProvider; import com.fr.stable.script.CalculatorProvider; -import redis.clients.jedis.Jedis; import java.util.ArrayList; import java.util.List; @@ -14,7 +14,7 @@ import java.util.Map; */ public class HashVisitor extends AbstractVisitor { @Override - public List> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception { + public List> getContent(CalculatorProvider calculator, ParameterProvider[] ps, EmbedRedis client, String query, int rowCount) throws Exception { String[] arr = query.trim().split(TOKEN_SPACE); if (arr.length < 2) { throw new IllegalArgumentException("Illegal query:" + query); diff --git a/src/main/java/com/fr/plugin/db/redis/core/visit/impl/KeysVisitor.java b/src/main/java/com/fr/plugin/db/redis/core/visit/impl/KeysVisitor.java index e597ef5..0636304 100644 --- a/src/main/java/com/fr/plugin/db/redis/core/visit/impl/KeysVisitor.java +++ b/src/main/java/com/fr/plugin/db/redis/core/visit/impl/KeysVisitor.java @@ -1,9 +1,9 @@ package com.fr.plugin.db.redis.core.visit.impl; +import com.fr.plugin.db.redis.core.accessor.EmbedRedis; import com.fr.plugin.db.redis.core.visit.AbstractVisitor; import com.fr.stable.ParameterProvider; import com.fr.stable.script.CalculatorProvider; -import redis.clients.jedis.Jedis; import java.util.ArrayList; import java.util.List; @@ -11,7 +11,7 @@ import java.util.Set; public class KeysVisitor extends AbstractVisitor { @Override - public List> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception { + public List> getContent(CalculatorProvider calculator, ParameterProvider[] ps, EmbedRedis client, String query, int rowCount) throws Exception { String[] arr = query.trim().split(TOKEN_SPACE); if (arr.length < 2) { throw new IllegalArgumentException("Illegal query:" + query); diff --git a/src/main/java/com/fr/plugin/db/redis/core/visit/impl/ListVisitor.java b/src/main/java/com/fr/plugin/db/redis/core/visit/impl/ListVisitor.java index 5600249..8779d86 100644 --- a/src/main/java/com/fr/plugin/db/redis/core/visit/impl/ListVisitor.java +++ b/src/main/java/com/fr/plugin/db/redis/core/visit/impl/ListVisitor.java @@ -1,10 +1,10 @@ package com.fr.plugin.db.redis.core.visit.impl; import com.fr.base.TableData; +import com.fr.plugin.db.redis.core.accessor.EmbedRedis; import com.fr.plugin.db.redis.core.visit.AbstractVisitor; import com.fr.stable.ParameterProvider; import com.fr.stable.script.CalculatorProvider; -import redis.clients.jedis.Jedis; import java.util.ArrayList; import java.util.List; @@ -14,7 +14,7 @@ import java.util.List; */ public class ListVisitor extends AbstractVisitor { @Override - public List> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception { + public List> getContent(CalculatorProvider calculator, ParameterProvider[] ps, EmbedRedis client, String query, int rowCount) throws Exception { String[] arr = query.trim().split(TOKEN_SPACE); if (arr.length < 4) { diff --git a/src/main/java/com/fr/plugin/db/redis/core/visit/impl/MGetVisitor.java b/src/main/java/com/fr/plugin/db/redis/core/visit/impl/MGetVisitor.java index 2528b38..bf4df51 100644 --- a/src/main/java/com/fr/plugin/db/redis/core/visit/impl/MGetVisitor.java +++ b/src/main/java/com/fr/plugin/db/redis/core/visit/impl/MGetVisitor.java @@ -1,10 +1,10 @@ package com.fr.plugin.db.redis.core.visit.impl; import com.fanruan.api.util.ArrayKit; +import com.fr.plugin.db.redis.core.accessor.EmbedRedis; import com.fr.plugin.db.redis.core.visit.AbstractVisitor; import com.fr.stable.ParameterProvider; import com.fr.stable.script.CalculatorProvider; -import redis.clients.jedis.Jedis; import java.util.ArrayList; import java.util.List; @@ -14,7 +14,7 @@ import java.util.List; */ public class MGetVisitor extends AbstractVisitor { @Override - public List> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception { + public List> getContent(CalculatorProvider calculator, ParameterProvider[] ps, EmbedRedis client, String query, int rowCount) throws Exception { String[] arr = query.trim().split(TOKEN_SPACE); if (arr.length < 2) { throw new IllegalArgumentException("Illegal query:" + query); diff --git a/src/main/java/com/fr/plugin/db/redis/core/visit/impl/SetVisitor.java b/src/main/java/com/fr/plugin/db/redis/core/visit/impl/SetVisitor.java index b602658..5c07be7 100644 --- a/src/main/java/com/fr/plugin/db/redis/core/visit/impl/SetVisitor.java +++ b/src/main/java/com/fr/plugin/db/redis/core/visit/impl/SetVisitor.java @@ -1,9 +1,9 @@ package com.fr.plugin.db.redis.core.visit.impl; +import com.fr.plugin.db.redis.core.accessor.EmbedRedis; import com.fr.plugin.db.redis.core.visit.AbstractVisitor; import com.fr.stable.ParameterProvider; import com.fr.stable.script.CalculatorProvider; -import redis.clients.jedis.Jedis; import java.util.ArrayList; import java.util.List; @@ -15,7 +15,7 @@ import java.util.Set; public class SetVisitor extends AbstractVisitor { @Override - public List> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception { + public List> getContent(CalculatorProvider calculator, ParameterProvider[] ps, EmbedRedis client, String query, int rowCount) throws Exception { String[] arr = query.trim().split(TOKEN_SPACE); if (arr.length < 2) { throw new IllegalArgumentException("Illegal query:" + query); diff --git a/src/main/java/com/fr/plugin/db/redis/core/visit/impl/ZRangeVisitor.java b/src/main/java/com/fr/plugin/db/redis/core/visit/impl/ZRangeVisitor.java index e3eb2d5..51374d8 100644 --- a/src/main/java/com/fr/plugin/db/redis/core/visit/impl/ZRangeVisitor.java +++ b/src/main/java/com/fr/plugin/db/redis/core/visit/impl/ZRangeVisitor.java @@ -1,10 +1,10 @@ package com.fr.plugin.db.redis.core.visit.impl; import com.fr.base.TableData; +import com.fr.plugin.db.redis.core.accessor.EmbedRedis; import com.fr.plugin.db.redis.core.visit.AbstractVisitor; import com.fr.stable.ParameterProvider; import com.fr.stable.script.CalculatorProvider; -import redis.clients.jedis.Jedis; import redis.clients.jedis.Tuple; import java.util.ArrayList; @@ -16,7 +16,7 @@ import java.util.Set; */ public class ZRangeVisitor extends AbstractVisitor { @Override - public List> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception { + public List> getContent(CalculatorProvider calculator, ParameterProvider[] ps, EmbedRedis client, String query, int rowCount) throws Exception { String[] arr = query.trim().split(TOKEN_SPACE); if (arr.length < 4) { throw new IllegalArgumentException("Illegal query:" + query); diff --git a/src/main/java/com/fr/plugin/db/redis/help/client/BaseRedisClient.java b/src/main/java/com/fr/plugin/db/redis/help/client/BaseRedisClient.java index 6c2931b..6815115 100644 --- a/src/main/java/com/fr/plugin/db/redis/help/client/BaseRedisClient.java +++ b/src/main/java/com/fr/plugin/db/redis/help/client/BaseRedisClient.java @@ -2,6 +2,7 @@ package com.fr.plugin.db.redis.help.client; import com.fanruan.api.log.LogKit; +import com.fr.plugin.db.redis.core.accessor.EmbedRedis; import com.fr.plugin.db.redis.help.ScriptBridge; import com.fr.plugin.db.redis.help.RedisClient; import redis.clients.jedis.Jedis; @@ -13,9 +14,9 @@ import redis.clients.jedis.Jedis; */ public abstract class BaseRedisClient implements RedisClient { - Jedis jedis; + EmbedRedis jedis; - BaseRedisClient(Jedis jedis) { + BaseRedisClient(EmbedRedis jedis) { this.jedis = jedis; } diff --git a/src/main/java/com/fr/plugin/db/redis/help/client/RedisNashornClient.java b/src/main/java/com/fr/plugin/db/redis/help/client/RedisNashornClient.java index 9aea761..e79d6bc 100644 --- a/src/main/java/com/fr/plugin/db/redis/help/client/RedisNashornClient.java +++ b/src/main/java/com/fr/plugin/db/redis/help/client/RedisNashornClient.java @@ -2,10 +2,10 @@ package com.fr.plugin.db.redis.help.client; import com.fanruan.api.log.LogKit; import com.fr.base.TableData; +import com.fr.plugin.db.redis.core.accessor.EmbedRedis; import com.fr.plugin.db.redis.core.emb.Redis; import com.fr.plugin.db.redis.help.Console; import com.fr.plugin.db.redis.help.ScriptBridge; -import redis.clients.jedis.Jedis; import javax.script.ScriptEngine; import javax.script.ScriptEngineFactory; @@ -31,7 +31,7 @@ public class RedisNashornClient extends BaseRedisClient { private V8 v8; - public RedisV8Client(Jedis jedis) { + public RedisV8Client(EmbedRedis jedis) { super(jedis); this.v8 = V8.createV8Runtime(); } @@ -35,7 +35,7 @@ public class RedisV8Client extends BaseRedisClient { @ScriptBridge public V8Array hkeys(String key) { long start = System.currentTimeMillis(); - Set set = jedis.keys(key); + Set set = jedis.hkeys(key); LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start); return V8ObjectUtils.toV8Array(v8, new ArrayList(set)); } @@ -82,7 +82,7 @@ public class RedisV8Client extends BaseRedisClient { long start = System.currentTimeMillis(); int len = keys.length(); String[] parameters = new String[len]; - for (int i = 0; i < len; i ++) { + for (int i = 0; i < len; i++) { parameters[i] = keys.getString(i); } List list = jedis.mget(parameters); diff --git a/src/main/java/com/fr/plugin/db/redis/ui/RedisConnectionPane.java b/src/main/java/com/fr/plugin/db/redis/ui/RedisConnectionPane.java index 50e7978..afd00a4 100755 --- a/src/main/java/com/fr/plugin/db/redis/ui/RedisConnectionPane.java +++ b/src/main/java/com/fr/plugin/db/redis/ui/RedisConnectionPane.java @@ -3,7 +3,6 @@ package com.fr.plugin.db.redis.ui; import com.fanruan.api.conf.ConfigurationKit; import com.fanruan.api.design.DesignKit; import com.fanruan.api.design.ui.component.UIActionLabel; -import com.fanruan.api.design.ui.component.UIIntNumberField; import com.fanruan.api.design.ui.component.UILabel; import com.fanruan.api.design.ui.component.UIPasswordField; import com.fanruan.api.design.ui.component.UITextField; @@ -25,11 +24,10 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; - public class RedisConnectionPane extends DatabaseConnectionPane { private UITextField hostTextField; - private UIIntNumberField portNumberField; + private UITextField portNumberField; private UIPasswordField passwordTextField; @@ -38,12 +36,12 @@ public class RedisConnectionPane extends DatabaseConnectionPane