Browse Source

支持连接redis集群

paid
richie 5 years ago
parent
commit
6e911d6a44
  1. 5
      plugin.xml
  2. 12
      src/main/java/com/fr/plugin/db/redis/core/RedisDatabaseConnection.java
  3. 87
      src/main/java/com/fr/plugin/db/redis/core/RedisPool.java
  4. 40
      src/main/java/com/fr/plugin/db/redis/core/accessor/EmbedRedis.java
  5. 118
      src/main/java/com/fr/plugin/db/redis/core/accessor/category/ClusterRedisClient.java
  6. 89
      src/main/java/com/fr/plugin/db/redis/core/accessor/category/StandaloneRedisClient.java
  7. 4
      src/main/java/com/fr/plugin/db/redis/core/emb/Redis.java
  8. 21
      src/main/java/com/fr/plugin/db/redis/core/emb/impl/ProxyRedis.java
  9. 21
      src/main/java/com/fr/plugin/db/redis/core/emb/impl/SimpleRedis.java
  10. 4
      src/main/java/com/fr/plugin/db/redis/core/visit/AbstractVisitor.java
  11. 6
      src/main/java/com/fr/plugin/db/redis/core/visit/Visitor.java
  12. 3
      src/main/java/com/fr/plugin/db/redis/core/visit/VisitorFactory.java
  13. 6
      src/main/java/com/fr/plugin/db/redis/core/visit/impl/GetVisitor.java
  14. 4
      src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashGetVisitor.java
  15. 4
      src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashKeysVisitor.java
  16. 4
      src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashMGetVisitor.java
  17. 4
      src/main/java/com/fr/plugin/db/redis/core/visit/impl/HashVisitor.java
  18. 4
      src/main/java/com/fr/plugin/db/redis/core/visit/impl/KeysVisitor.java
  19. 4
      src/main/java/com/fr/plugin/db/redis/core/visit/impl/ListVisitor.java
  20. 4
      src/main/java/com/fr/plugin/db/redis/core/visit/impl/MGetVisitor.java
  21. 4
      src/main/java/com/fr/plugin/db/redis/core/visit/impl/SetVisitor.java
  22. 4
      src/main/java/com/fr/plugin/db/redis/core/visit/impl/ZRangeVisitor.java
  23. 5
      src/main/java/com/fr/plugin/db/redis/help/client/BaseRedisClient.java
  24. 4
      src/main/java/com/fr/plugin/db/redis/help/client/RedisNashornClient.java
  25. 10
      src/main/java/com/fr/plugin/db/redis/help/client/RedisV8Client.java
  26. 25
      src/main/java/com/fr/plugin/db/redis/ui/RedisConnectionPane.java
  27. 3
      src/main/resources/com/fr/plugin/db/redis/locale/redis.properties
  28. 3
      src/main/resources/com/fr/plugin/db/redis/locale/redis_en_US.properties
  29. 5
      src/main/resources/com/fr/plugin/db/redis/locale/redis_zh_CN.properties

5
plugin.xml

@ -3,12 +3,13 @@
<id>com.fr.solution.plugin.db.redis.v10</id>
<name><![CDATA[Redis数据集]]></name>
<active>yes</active>
<version>6.2</version>
<version>7.0</version>
<env-version>10.0</env-version>
<jartime>2018-11-29</jartime>
<jartime>2019-07-29</jartime>
<vendor>richie</vendor>
<description><![CDATA[可以连接Redis数据库,支持哈希表、列表、集合以及有序集合]]></description>
<change-notes><![CDATA[
[2019-09-18]支持连接redis集群。<br/>
[2019-08-26]给console增加一个engine()函数,判断使用的脚本引擎名字。<br/>
[2019-08-26]不支持V8引擎的机器上使用JDK内置的脚本引擎(仅支持ES5语法)。<br/>
[2019-03-21]现在可以通过跳板服务连接redis。<br/>

12
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<String> host = HolderKit.simple(StringKit.EMPTY);
private Conf<Integer> port = HolderKit.simple(DEFAULT_REDIS_PORT);
private Conf<String> port = HolderKit.simple(String.valueOf(DEFAULT_REDIS_PORT));
private Conf<String> 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<String>) host.clone();
cloned.port = (Conf<Integer>) port.clone();
cloned.port = (Conf<String>) port.clone();
cloned.password = (Conf<String>) password.clone();
return cloned;
}

87
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<String, JedisPool> jedisPoolMap = new ConcurrentHashMap<String, JedisPool>();
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<Pair<String, Integer>> 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<String, Integer> 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<Pair<String, Integer>> 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<HostAndPort> nodes = new LinkedHashSet<HostAndPort>();
for (Pair<String, Integer> 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<Pair<String, Integer>> findAllHostAndPassword(String host, String port) {
String[] hostArray = host.split(",");
String[] portArray = port.split(",");
int len = ArrayKit.getLength(hostArray);
List<Pair<String, Integer>> pairs = new ArrayList<Pair<String, Integer>>();
for (int i = 0; i < len; i++) {
pairs.add(new Pair<String, Integer>(hostArray[i], Integer.parseInt(portArray[i])));
}
return pairs;
}
}

40
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<String> keys(String pattern);
String get(String key);
String hget(String key, String field);
List<String> hmget(String key, String... fields);
Map<String, String> hgetAll(String key);
Set<String> hkeys(String key);
List<String> lrange(String key, long start, long end);
List<String> mget(String... keys);
Set<String> smembers(String key);
Set<Tuple> zrangeWithScores(final String key, final long start, final long end);
void select(int index);
String ping();
}

118
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<String> keys(String pattern) {
TreeSet<String> keys = new TreeSet<String>();
Map<String, JedisPool> 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<String> hmget(String key, String... fields) {
return jedisCluster.hmget(key, fields);
}
@Override
public Map<String, String> hgetAll(String key) {
return jedisCluster.hgetAll(key);
}
@Override
public Set<String> hkeys(String key) {
return jedisCluster.hkeys(key);
}
@Override
public List<String> lrange(String key, long start, long end) {
return jedisCluster.lrange(key, start, end);
}
@Override
public List<String> mget(String... keys) {
return jedisCluster.mget(keys);
}
@Override
public Set<String> smembers(String key) {
return jedisCluster.smembers(key);
}
@Override
public Set<Tuple> 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<String, JedisPool> 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();
}
}

89
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<String> 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<String> hmget(String key, String... fields) {
return jedis.hmget(key, fields);
}
@Override
public Map<String, String> hgetAll(String key) {
return jedis.hgetAll(key);
}
@Override
public Set<String> hkeys(String key) {
return jedis.hkeys(key);
}
@Override
public List<String> lrange(String key, long start, long end) {
return jedis.lrange(key, start, end);
}
@Override
public List<String> mget(String... keys) {
return jedis.mget(keys);
}
@Override
public Set<String> smembers(String key) {
return jedis.smembers(key);
}
@Override
public Set<Tuple> 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();
}
}

4
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();
}

21
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();
}
}

21
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);
}
}
}

4
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<T> implements Visitor<T> {
@Override
public DataWrapper<T> buildData(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception {
public DataWrapper<T> 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);
}

6
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<T> {
String TOKEN_SPACE = "\\s+";
List<List<T>> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception;
List<List<T>> getContent(CalculatorProvider calculator, ParameterProvider[] ps, EmbedRedis client, String query, int rowCount) throws Exception;
DataWrapper<T> buildData(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception;
DataWrapper<T> buildData(CalculatorProvider calculator, ParameterProvider[] ps, EmbedRedis client, String query, int rowCount) throws Exception;
boolean match(String query);

3
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 <T> DataWrapper<T> getKeyValueResult(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception {
public static <T> DataWrapper<T> getKeyValueResult(CalculatorProvider calculator, ParameterProvider[] ps, EmbedRedis client, String query, int rowCount) throws Exception {
Visitor visitor = getMatchedVisitor(query);
if (visitor == null) {
return DataWrapper.EMPTY;

6
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<String> {
public class GetVisitor extends AbstractVisitor<String> {
@Override
public List<List<String>> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception {
public List<List<String>> 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);

4
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 <String>{
@Override
public List<List<String>> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception {
public List<List<String>> 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);

4
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<String> {
@Override
public List<List<String>> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception {
public List<List<String>> 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);

4
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<String>{
@Override
public List<List<String>> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception {
public List<List<String>> 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);

4
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<String> {
@Override
public List<List<String>> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception {
public List<List<String>> 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);

4
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<String> {
@Override
public List<List<String>> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception {
public List<List<String>> 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);

4
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<String> {
@Override
public List<List<String>> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception {
public List<List<String>> getContent(CalculatorProvider calculator, ParameterProvider[] ps, EmbedRedis client, String query, int rowCount) throws Exception {
String[] arr = query.trim().split(TOKEN_SPACE);
if (arr.length < 4) {

4
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<String> {
@Override
public List<List<String>> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception {
public List<List<String>> 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);

4
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<String> {
@Override
public List<List<String>> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception {
public List<List<String>> 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);

4
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<Object> {
@Override
public List<List<Object>> getContent(CalculatorProvider calculator, ParameterProvider[] ps, Jedis client, String query, int rowCount) throws Exception {
public List<List<Object>> 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);

5
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<A, O> implements RedisClient<A, O> {
Jedis jedis;
EmbedRedis jedis;
BaseRedisClient(Jedis jedis) {
BaseRedisClient(EmbedRedis jedis) {
this.jedis = jedis;
}

4
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<Object[], Map<Object, Ob
private ScriptEngine scriptEngine;
public RedisNashornClient(Jedis jedis) {
public RedisNashornClient(EmbedRedis jedis) {
super(jedis);
this.scriptEngine = findScriptEngine();
}

10
src/main/java/com/fr/plugin/db/redis/help/client/RedisV8Client.java

@ -4,13 +4,13 @@ import com.eclipsesource.v8.V8;
import com.eclipsesource.v8.V8Array;
import com.eclipsesource.v8.V8Object;
import com.eclipsesource.v8.utils.V8ObjectUtils;
import com.fr.base.TableData;
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 com.fr.plugin.db.redis.util.RedisUtils;
import redis.clients.jedis.Jedis;
import java.util.ArrayList;
import java.util.List;
@ -26,7 +26,7 @@ public class RedisV8Client extends BaseRedisClient<V8Array, V8Object> {
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<V8Array, V8Object> {
@ScriptBridge
public V8Array hkeys(String key) {
long start = System.currentTimeMillis();
Set<String> set = jedis.keys(key);
Set<String> set = jedis.hkeys(key);
LogKit.info("Fetch data from redis spend time {} ms.", System.currentTimeMillis() - start);
return V8ObjectUtils.toV8Array(v8, new ArrayList<String>(set));
}
@ -82,7 +82,7 @@ public class RedisV8Client extends BaseRedisClient<V8Array, V8Object> {
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<String> list = jedis.mget(parameters);

25
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<RedisDatabaseConnection> {
private UITextField hostTextField;
private UIIntNumberField portNumberField;
private UITextField portNumberField;
private UIPasswordField passwordTextField;
@ -38,12 +36,12 @@ public class RedisConnectionPane extends DatabaseConnectionPane<RedisDatabaseCon
JPanel pane = new JPanel();
pane.setLayout(new BorderLayout());
hostTextField = new UITextField();
portNumberField = new UIIntNumberField();
portNumberField = new UITextField();
passwordTextField = new UIPasswordField();
JPanel globalConfigPane = new JPanel();
GridLayout gridLayout = new GridLayout(1, 2);
GridLayout gridLayout = new GridLayout(1, 3);
globalConfigPane.setLayout(gridLayout);
Component[][] components = new Component[][]{
@ -55,6 +53,7 @@ public class RedisConnectionPane extends DatabaseConnectionPane<RedisDatabaseCon
UIActionLabel poolConfigLabel = new UIActionLabel(DesignKit.i18nText("Plugin-Redis_Pool_Config"));
UIActionLabel proxyConfigLabel = new UIActionLabel(DesignKit.i18nText("Plugin-Redis_Proxy_Config"));
UIActionLabel clusterConfigLabel = new UIActionLabel(DesignKit.i18nText("Plugin-Redis_Connect_Cluster_Description"));
poolConfigLabel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@ -95,8 +94,20 @@ public class RedisConnectionPane extends DatabaseConnectionPane<RedisDatabaseCon
dialog.setVisible(true);
}
});
clusterConfigLabel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(
SwingUtilities.getWindowAncestor(RedisConnectionPane.this),
DesignKit.i18nText("Plugin-Redis_Cluster_Config_Description"),
DesignKit.i18nText("Plugin-Redis_Connect_Cluster_Description"),
JOptionPane.INFORMATION_MESSAGE
);
}
});
globalConfigPane.add(GUICoreKit.createFlowPane(poolConfigLabel, FlowLayout.LEFT));
globalConfigPane.add(GUICoreKit.createFlowPane(proxyConfigLabel, FlowLayout.LEFT));
globalConfigPane.add(GUICoreKit.createFlowPane(clusterConfigLabel, FlowLayout.LEFT));
double p = TableLayoutKit.PREFERRED;
double[] rowSize = new double[]{p, p, p, p, p};
@ -116,7 +127,7 @@ public class RedisConnectionPane extends DatabaseConnectionPane<RedisDatabaseCon
@Override
protected void populateSubDatabaseConnectionBean(RedisDatabaseConnection ob) {
hostTextField.setText(ob.getHost());
portNumberField.setValue(ob.getPort());
portNumberField.setText(ob.getPort());
passwordTextField.setText(ob.getPassword());
}
@ -124,7 +135,7 @@ public class RedisConnectionPane extends DatabaseConnectionPane<RedisDatabaseCon
protected com.fr.plugin.db.redis.core.RedisDatabaseConnection updateSubDatabaseConnectionBean() {
RedisDatabaseConnection connection = new RedisDatabaseConnection();
connection.setHost(hostTextField.getText());
connection.setPort((int) portNumberField.getValue());
connection.setPort(portNumberField.getText());
connection.setPassword(passwordTextField.getText());
return connection;
}

3
src/main/resources/com/fr/plugin/db/redis/locale/redis.properties

@ -15,7 +15,6 @@ Plugin-Redis_Formula=Formula
Plugin-Redis_Query=Query
Plugin-Redis_Connection_Successfully=Connection Successfully
Plugin-Redis_Connection_Failed=Connection Failed
Plugin-Redis_Script_Text=Transform Script
Plugin-Redis_Script_Text_Description=Script Description
Plugin-Redis_Pool_Max_Total=Max Total
Plugin-Redis_Script_Query_Text=Query Script
@ -34,3 +33,5 @@ Plugin-Redis_Pool_Lifo=Lifo
Plugin-Redis_Pool_Max_Idle=Max Idle
Plugin-Redis_Pool_Timeout=Timeout
Plugin-Redis_Proxy_Description=Only Support SSH Protocol
Plugin-Redis_Connect_Cluster_Description=Connect Cluster Description
Plugin-Redis_Cluster_Config_Description=Input multiple hosts with commas separator.

3
src/main/resources/com/fr/plugin/db/redis/locale/redis_en_US.properties

@ -15,7 +15,6 @@ Plugin-Redis_Formula=Formula
Plugin-Redis_Query=Query
Plugin-Redis_Connection_Successfully=Connection Successfully
Plugin-Redis_Connection_Failed=Connection Failed
Plugin-Redis_Script_Text=Transform Script
Plugin-Redis_Script_Text_Description=Script Description
Plugin-Redis_Pool_Max_Total=Max Total
Plugin-Redis_Script_Query_Text=Query Script
@ -34,3 +33,5 @@ Plugin-Redis_Pool_Lifo=Lifo
Plugin-Redis_Pool_Max_Idle=Max Idle
Plugin-Redis_Pool_Timeout=Timeout
Plugin-Redis_Proxy_Description=Only Support SSH Protocol
Plugin-Redis_Connect_Cluster_Description=Connect Cluster Description
Plugin-Redis_Cluster_Config_Description=Input multiple hosts with commas separator.

5
src/main/resources/com/fr/plugin/db/redis/locale/redis_zh_CN.properties

@ -15,7 +15,6 @@ Plugin-Redis_Formula=\u516C\u5F0F
Plugin-Redis_Query=\u67E5\u8BE2
Plugin-Redis_Connection_Successfully=\u8FDE\u63A5\u6210\u529F
Plugin-Redis_Connection_Failed=\u8FDE\u63A5\u5931\u8D25
Plugin-Redis_Script_Text=\u8F6C\u6362\u811A\u672C
Plugin-Redis_Script_Text_Description=\u53EF\u4EE5\u4F7F\u7528JavaScript\u811A\u672C\u6765\u8F6C\u6362\u67E5\u8BE2\u7ED3\u679C\u3002\n\u6CE8\u610F1\uFF1A\u5185\u7F6E\u53C2\u6570$content\u548C$column\uFF0C\u5206\u522B\u8868\u793A\u539F\u59CB\u7684\u6570\u636E\u96C6\u5185\u5BB9\uFF08\u4E8C\u7EF4\u6570\u7EC4\uFF09\u548C\u6570\u636E\u96C6\u7684\u5217\u540D\uFF08\u4E00\u7EF4\u6570\u7EC4\uFF09\u3002\u5982\u679C\u8FD4\u56DE\u4E00\u4E2A\u4E8C\u7EF4\u6570\u7EC4\uFF0C\u8868\u793A\u4EC5\u4FEE\u6539\u6570\u636E\u96C6\u5185\u5BB9\uFF0C\u4E0D\u4FEE\u6539\u6570\u636E\u96C6\u7684\u5217\u540D\uFF1B\u5982\u679C\u8FD4\u56DE\u4E00\u4E2A\u5982\u4E0B\u683C\u5F0F\u7684\u5BF9\u8C61:\
{content:[][],column:[]}\uFF0C\u8868\u793A\u540C\u65F6\u4FEE\u6539\u4E86\u6570\u636E\u96C6\u7684\u5185\u5BB9\u548C\u5217\u540D\u3002\n\u6CE8\u610F2\uFF1A\u5982\u679C\u5E0C\u671B\u5F15\u7528\u5916\u90E8JS\uFF0C\u53EF\u4EE5\u5728\u811A\u672C\u6846\u4E2D\u5199\u5165file:///$ENV_HOME/transform.js\uFF0C\u5176\u4E2D$ENV_HOME\u8868\u793A\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55\u3002
Plugin-Redis_Pool_Max_Total=\u6700\u5927\u8FDE\u63A5\u6570
@ -34,4 +33,6 @@ Plugin-Redis_Pool_Block_When_Exhausted=\u8FDE\u63A5\u8017\u5C3D\u65F6\u963B\u585
Plugin-Redis_Pool_Lifo=\u540E\u8FDB\u5148\u51FA
Plugin-Redis_Pool_Max_Idle=\u6700\u5927\u7A7A\u95F2\u8FDE\u63A5\u6570
Plugin-Redis_Pool_Timeout=\u8D85\u65F6\u65F6\u95F4
Plugin-Redis_Proxy_Description=\u8DF3\u677F\u670D\u52A1\u5668\u8FDE\u63A5\u4EC5\u652F\u6301ssh\u534F\u8BAE\uFF08\u6CE8\u610F\uFF1A\u542F\u7528\u8DF3\u677F\u670D\u52A1\u5668\u5C06\u65E0\u6CD5\u4F7F\u7528\u8FDE\u63A5\u6C60\uFF09
Plugin-Redis_Proxy_Description=\u8DF3\u677F\u670D\u52A1\u5668\u8FDE\u63A5\u4EC5\u652F\u6301ssh\u534F\u8BAE\uFF08\u6CE8\u610F\uFF1A\u542F\u7528\u8DF3\u677F\u670D\u52A1\u5668\u5C06\u65E0\u6CD5\u4F7F\u7528\u8FDE\u63A5\u6C60\uFF09
Plugin-Redis_Connect_Cluster_Description=\u8FDE\u63A5\u96C6\u7FA4\u914D\u7F6E\u8BF4\u660E
Plugin-Redis_Cluster_Config_Description=1\u3001\u4F7F\u7528\u9017\u53F7\u5206\u5272\u96C6\u7FA4\u4E2D\u7684\u591A\u4E2A\u6570\u636E\u5E93\u5730\u5740\u548C\u7AEF\u53E3\uFF0C\u5FC5\u987B\u8981\u6C42\u5730\u5740\u548C\u7AEF\u53E3\u6570\u91CF\u4E00\u81F4\uFF1B\n2\u3001\u6240\u6709redis\u8282\u70B9\u7684\u5BC6\u7801\u5FC5\u987B\u76F8\u540C;\n3\u3001\u8FDE\u63A5\u96C6\u7FA4\u7684\u65F6\u5019\u65E0\u6CD5\u4F7F\u7528\u8DF3\u677F\u673A\u3002
Loading…
Cancel
Save