diff --git a/lib/finekit-10.0.jar b/lib/finekit-10.0.jar index 34ff820..01f000d 100644 Binary files a/lib/finekit-10.0.jar and b/lib/finekit-10.0.jar differ diff --git a/plugin.xml b/plugin.xml index edfa5fa..ca9a779 100755 --- a/plugin.xml +++ b/plugin.xml @@ -3,12 +3,13 @@ com.fr.solution.plugin.db.redis.v10 yes - 7.1 + 7.2 10.0 2019-03-29 richie [2019-09-29]修复无法兼容老版本的问题。
[2019-09-18]支持手动选择不同JavaScript脚本引擎。
[2019-09-18]支持连接redis集群。
@@ -39,6 +40,9 @@ + + + diff --git a/src/main/java/com/fr/plugin/db/redis/RedisHttpHandlerProvider.java b/src/main/java/com/fr/plugin/db/redis/RedisHttpHandlerProvider.java new file mode 100644 index 0000000..aa9d2eb --- /dev/null +++ b/src/main/java/com/fr/plugin/db/redis/RedisHttpHandlerProvider.java @@ -0,0 +1,19 @@ +package com.fr.plugin.db.redis; + +import com.fr.decision.fun.HttpHandler; +import com.fr.decision.fun.impl.AbstractHttpHandlerProvider; +import com.fr.plugin.db.redis.action.SearchKeysAction; + +/** + * @author Elijah + * @version 10.0.4 + * Created by Elijah on 2019/10/30 + */ +public class RedisHttpHandlerProvider extends AbstractHttpHandlerProvider { + @Override + public HttpHandler[] registerHandlers() { + return new HttpHandler[] { + new SearchKeysAction() + }; + } +} \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/db/redis/RedisScriptUniversalTableDataImpl.java b/src/main/java/com/fr/plugin/db/redis/RedisScriptUniversalTableDataImpl.java new file mode 100644 index 0000000..9677a07 --- /dev/null +++ b/src/main/java/com/fr/plugin/db/redis/RedisScriptUniversalTableDataImpl.java @@ -0,0 +1,76 @@ +package com.fr.plugin.db.redis; + +import com.fanruan.api.cal.FormulaKit; +import com.fanruan.api.data.ConnectionKit; +import com.fanruan.api.data.TableDataKit; +import com.fanruan.api.util.StringKit; +import com.fr.data.impl.Connection; +import com.fr.decision.fun.impl.AbstractUniversalServerTableDataProvider; +import com.fr.json.JSONObject; +import com.fr.plugin.db.redis.bean.ParameterBean; +import com.fr.plugin.db.redis.core.RedisConstants; +import com.fr.plugin.db.redis.core.RedisScriptTableData; +import com.fr.plugin.db.redis.core.order.impl.FormulaOrderValue; +import com.fr.plugin.db.redis.core.order.impl.NumberOrderValue; +import com.fr.plugin.db.redis.core.script.EngineType; +import com.fr.plugin.db.redis.util.RedisUtils; +import com.fr.script.Calculator; +import com.fr.stable.NameReference; +import com.fr.web.struct.Atom; + +/** + * @author Elijah + * @version 10.0.4 + * Created by Elijah on 2019/10/30 + */ +public class RedisScriptUniversalTableDataImpl extends AbstractUniversalServerTableDataProvider { + + @Override + public Class classForTableData() { + return RedisScriptTableData.class; + } + + @Override + public String nameForTableData() { + return "RedisScript"; + } + + @Override + public JSONObject serialize(RedisScriptTableData redisScriptTableData) { + JSONObject data = new JSONObject(); + Connection database = redisScriptTableData.getDatabase(); + data.put(RedisConstants.DATABASE, database instanceof NameReference ? ((NameReference) database).getName() : StringKit.EMPTY); + data.put(RedisConstants.ORDER, redisScriptTableData.getOrderValue().toString()); + data.put(RedisConstants.SCRIPT, redisScriptTableData.getScript()); + data.put(RedisConstants.ENGINE, redisScriptTableData.getEngineType().getType()); + data.put(RedisConstants.PARAMETERS, ParameterBean.createParameterBeans(redisScriptTableData.getParameters(Calculator.createCalculator()))); + return data; + } + + @Override + public RedisScriptTableData deserialize(RedisScriptTableData oldTableData, JSONObject data) { + RedisScriptTableData newTableData = new RedisScriptTableData(); + String databaseName = data.getString(RedisConstants.DATABASE); + String script = data.getString(RedisConstants.SCRIPT); + if (!StringKit.isEmpty(databaseName) && TableDataKit.findTableData(databaseName) != null) { + newTableData.setDatabase(ConnectionKit.createNameConnection(databaseName)); + } + newTableData.setEngineType(EngineType.parse(data.getInt(RedisConstants.ENGINE))); + newTableData.setScript(script); + Object order = data.get(RedisConstants.ORDER); + if (order instanceof Integer) { + newTableData.setOrderValue(new NumberOrderValue((Integer) order)); + } else { + newTableData.setOrderValue(new FormulaOrderValue(FormulaKit.newFormula(order))); + } + + newTableData.setParameters(RedisUtils.analyzeParameter(oldTableData.getParameters(Calculator.createCalculator()), newTableData.getOrderValue(), script)); + + return newTableData; + } + + @Override + public Atom client() { + return RedisConnectionComponent.KEY; + } +} \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/db/redis/RedisUniversalTableDataImpl.java b/src/main/java/com/fr/plugin/db/redis/RedisUniversalTableDataImpl.java new file mode 100644 index 0000000..b29e4e2 --- /dev/null +++ b/src/main/java/com/fr/plugin/db/redis/RedisUniversalTableDataImpl.java @@ -0,0 +1,75 @@ +package com.fr.plugin.db.redis; + +import com.fanruan.api.cal.FormulaKit; +import com.fanruan.api.data.ConnectionKit; +import com.fanruan.api.data.TableDataKit; +import com.fanruan.api.util.StringKit; +import com.fr.data.impl.Connection; +import com.fr.decision.fun.impl.AbstractUniversalServerTableDataProvider; +import com.fr.json.JSONObject; +import com.fr.plugin.db.redis.bean.ParameterBean; +import com.fr.plugin.db.redis.core.RedisConstants; +import com.fr.plugin.db.redis.core.RedisTableData; +import com.fr.plugin.db.redis.core.order.impl.FormulaOrderValue; +import com.fr.plugin.db.redis.core.order.impl.NumberOrderValue; +import com.fr.plugin.db.redis.util.RedisUtils; +import com.fr.script.Calculator; +import com.fr.stable.NameReference; +import com.fr.web.struct.Atom; + +/** + * @author Elijah + * @version 10.0.4 + * Created by Elijah on 2019/10/30 + */ +public class RedisUniversalTableDataImpl extends AbstractUniversalServerTableDataProvider { + + @Override + public Class classForTableData() { + return RedisTableData.class; + } + + @Override + public String nameForTableData() { + return "Redis"; + } + + @Override + public JSONObject serialize(RedisTableData redisTableData) { + JSONObject data = new JSONObject(); + Connection database = redisTableData.getDatabase(); + data.put(RedisConstants.DATABASE, database instanceof NameReference ? ((NameReference) database).getName() : StringKit.EMPTY); + data.put(RedisConstants.ORDER, redisTableData.getOrderValue().toString()); + data.put(RedisConstants.SCRIPT, redisTableData.getScript()); + data.put(RedisConstants.QUERY, redisTableData.getQuery()); + data.put(RedisConstants.PARAMETERS, ParameterBean.createParameterBeans(redisTableData.getParameters(Calculator.createCalculator()))); + return data; + } + + @Override + public RedisTableData deserialize(RedisTableData oldTableData, JSONObject data) { + RedisTableData newTableData = oldTableData; + String databaseName = data.getString(RedisConstants.DATABASE); + String script = data.getString(RedisConstants.SCRIPT); + String query = data.getString(RedisConstants.QUERY); + if (!StringKit.isEmpty(databaseName) && TableDataKit.findTableData(databaseName) != null) { + newTableData.setDatabase(ConnectionKit.createNameConnection(databaseName)); + } + newTableData.setScript(script); + newTableData.setQuery(query); + //与前台约定,数字说明是序号 + Object order = data.get(RedisConstants.ORDER); + if (order instanceof Integer) { + newTableData.setOrderValue(new NumberOrderValue((Integer) order)); + } else { + newTableData.setOrderValue(new FormulaOrderValue(FormulaKit.newFormula(order))); + } + newTableData.setParameters(RedisUtils.analyzeParameter(oldTableData.getParameters(Calculator.createCalculator()), newTableData.getOrderValue(), script, query)); + return newTableData; + } + + @Override + public Atom client() { + return RedisConnectionComponent.KEY; + } +} \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/db/redis/action/SearchKeysAction.java b/src/main/java/com/fr/plugin/db/redis/action/SearchKeysAction.java new file mode 100644 index 0000000..29e13da --- /dev/null +++ b/src/main/java/com/fr/plugin/db/redis/action/SearchKeysAction.java @@ -0,0 +1,52 @@ +package com.fr.plugin.db.redis.action; + +import com.fanruan.api.data.ConnectionKit; +import com.fanruan.api.util.StringKit; +import com.fanruan.api.web.FlushKit; +import com.fr.base.ServerConfig; +import com.fr.data.impl.Connection; +import com.fr.decision.fun.impl.BaseHttpHandler; +import com.fr.json.JSONFactory; +import com.fr.plugin.db.redis.core.RedisDatabaseConnection; +import com.fr.third.springframework.web.bind.annotation.RequestMethod; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.Arrays; + +/** + * @author Elijah + * @version 10.0.4 + * Created by Elijah on 2019/10/30 + */ +public class SearchKeysAction extends BaseHttpHandler { + @Override + public RequestMethod getMethod() { + return RequestMethod.GET; + } + + @Override + public String getPath() { + return "/redis/keys"; + } + + @Override + public boolean isPublic() { + return false; + } + + @Override + public void handle(HttpServletRequest request, HttpServletResponse response) throws Exception { + String[] keys = new String[0]; + String pattern = request.getParameter("pattern"); + String connectionName = request.getParameter("database"); + if (StringKit.isNotEmpty(pattern) && StringKit.isNotEmpty(connectionName)) { + Connection connection = ConnectionKit.getConnection(connectionName); + if (connection instanceof RedisDatabaseConnection) { + keys = connection.summary(pattern); + } + } + FlushKit.printAsJSON(response, JSONFactory.createJSON(Arrays.asList(keys))); + response.setContentType("application/json;charset=" + ServerConfig.getInstance().getServerCharset()); + } +} \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/db/redis/bean/ParameterBean.java b/src/main/java/com/fr/plugin/db/redis/bean/ParameterBean.java new file mode 100644 index 0000000..0417609 --- /dev/null +++ b/src/main/java/com/fr/plugin/db/redis/bean/ParameterBean.java @@ -0,0 +1,72 @@ +package com.fr.plugin.db.redis.bean; + +import com.fr.base.ParameterTypeHandler; +import com.fr.stable.ParameterProvider; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Elijah + * @version 10.0.4 + * Created by Elijah on 2019/10/30 + */ +public class ParameterBean{ + public static final String TYPE = "type"; + public static final String NAME = "name"; + public static final String VALUE = "value"; + + private String type = ParameterTypeHandler.String.name(); + private String name; + private String value; + + public ParameterBean() { + } + + public ParameterBean(String name, String value) { + this.name = name; + this.value = value; + } + + public ParameterBean(String type, String name, String value) { + this.type = type; + this.name = name; + this.value = value; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public static ParameterBean createBean(ParameterProvider parameterProvider) { + return new ParameterBean(parameterProvider.getClass().getSimpleName(),parameterProvider.getName(), parameterProvider.valueToString()); + } + + public static List createParameterBeans(ParameterProvider[] parameterProviders) { + List parameterBeans = new ArrayList(); + for (ParameterProvider parameterProvider: parameterProviders) { + parameterBeans.add(ParameterBean.createBean(parameterProvider)); + } + return parameterBeans; + } +} \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/db/redis/core/RedisConstants.java b/src/main/java/com/fr/plugin/db/redis/core/RedisConstants.java index a1cb729..2a01b73 100755 --- a/src/main/java/com/fr/plugin/db/redis/core/RedisConstants.java +++ b/src/main/java/com/fr/plugin/db/redis/core/RedisConstants.java @@ -7,4 +7,11 @@ public class RedisConstants { public static final int DEFAULT_DB_INDEX = 0; public static final String[] DEFAULT_COLUMN_NAMES = new String[]{"text", "value"}; + + public static final String DATABASE= "database"; + public static final String QUERY = "query"; + public static final String SCRIPT = "script"; + public static final String ORDER = "orderValue"; + public static final String ENGINE = "engineType"; + public static final String PARAMETERS = "parameters"; } diff --git a/src/main/java/com/fr/plugin/db/redis/util/RedisUtils.java b/src/main/java/com/fr/plugin/db/redis/util/RedisUtils.java index 5e59809..2735e48 100644 --- a/src/main/java/com/fr/plugin/db/redis/util/RedisUtils.java +++ b/src/main/java/com/fr/plugin/db/redis/util/RedisUtils.java @@ -1,10 +1,12 @@ package com.fr.plugin.db.redis.util; import com.eclipsesource.v8.V8Object; +import com.fanruan.api.cal.ParameterKit; import com.fanruan.api.util.ArrayKit; import com.fanruan.api.util.GeneralKit; import com.fanruan.api.util.RenderKit; import com.fanruan.api.util.StringKit; +import com.fr.plugin.db.redis.core.order.OrderValue; import com.fr.plugin.db.redis.help.ScriptBridge; import com.fr.stable.ParameterProvider; import redis.clients.jedis.Jedis; @@ -69,4 +71,19 @@ public class RedisUtils { return StringKit.EMPTY; } } + + public static ParameterProvider[] analyzeParameter(ParameterProvider[] oldParameters, OrderValue orderValue, String ...parameterTexts) { + ParameterProvider[] newParameters = ParameterKit.analyzeAndUnionSameParameters(parameterTexts, oldParameters); + ParameterProvider[] newOrderParameters = orderValue.analyze4Parameters(); + Map parameterProviderMap = new HashMap(); + for (ParameterProvider parameterProvider: oldParameters) { + parameterProviderMap.put(parameterProvider.getName(), parameterProvider); + } + for (ParameterProvider parameterProvider: newOrderParameters) { + if (parameterProviderMap.containsKey(parameterProvider.getName())) { + parameterProvider.setValue(parameterProviderMap.get(parameterProvider.getName()).getValue()); + } + } + return ArrayKit.addAll(newParameters, newOrderParameters); + } }