|
|
@ -5,7 +5,7 @@ import com.fr.base.TableData; |
|
|
|
import com.fr.plugin.db.redis.core.emb.Redis; |
|
|
|
import com.fr.plugin.db.redis.core.emb.Redis; |
|
|
|
import com.fr.plugin.db.redis.help.Console; |
|
|
|
import com.fr.plugin.db.redis.help.Console; |
|
|
|
import com.fr.plugin.db.redis.help.ScriptBridge; |
|
|
|
import com.fr.plugin.db.redis.help.ScriptBridge; |
|
|
|
import com.fr.third.redis.clients.jedis.Jedis; |
|
|
|
import redis.clients.jedis.Jedis; |
|
|
|
|
|
|
|
|
|
|
|
import javax.script.ScriptEngine; |
|
|
|
import javax.script.ScriptEngine; |
|
|
|
import javax.script.ScriptEngineFactory; |
|
|
|
import javax.script.ScriptEngineFactory; |
|
|
@ -27,7 +27,7 @@ public class RedisNashornClient extends BaseRedisClient<Object[], Map<Object, Ob |
|
|
|
|
|
|
|
|
|
|
|
private static final String PREPARE_SCRIPT = |
|
|
|
private static final String PREPARE_SCRIPT = |
|
|
|
"function unique(array) {var res = [];for (var i = 0, arrayLen = array.length; i < arrayLen; i++) {for (var j = 0, resLen = res.length; j < resLen; j++ ) {if (array[i] === res[j]) {break;}} if (j === resLen) {res.push(array[i])}} return res;}\n" + |
|
|
|
"function unique(array) {var res = [];for (var i = 0, arrayLen = array.length; i < arrayLen; i++) {for (var j = 0, resLen = res.length; j < resLen; j++ ) {if (array[i] === res[j]) {break;}} if (j === resLen) {res.push(array[i])}} return res;}\n" + |
|
|
|
"function merge(table, column) {return {content:table, column:column}};"; |
|
|
|
"function merge(table, column) {return {content:table, column:column}};"; |
|
|
|
|
|
|
|
|
|
|
|
private ScriptEngine scriptEngine; |
|
|
|
private ScriptEngine scriptEngine; |
|
|
|
|
|
|
|
|
|
|
@ -87,7 +87,7 @@ public class RedisNashornClient extends BaseRedisClient<Object[], Map<Object, Ob |
|
|
|
long start = System.currentTimeMillis(); |
|
|
|
long start = System.currentTimeMillis(); |
|
|
|
int len = keys.length; |
|
|
|
int len = keys.length; |
|
|
|
String[] parameters = new String[len]; |
|
|
|
String[] parameters = new String[len]; |
|
|
|
for (int i = 0; i < len; i ++) { |
|
|
|
for (int i = 0; i < len; i++) { |
|
|
|
parameters[i] = String.valueOf(keys[i]); |
|
|
|
parameters[i] = String.valueOf(keys[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
List<String> list = jedis.mget(parameters); |
|
|
|
List<String> list = jedis.mget(parameters); |
|
|
@ -107,6 +107,7 @@ public class RedisNashornClient extends BaseRedisClient<Object[], Map<Object, Ob |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public SimpleDataModel build(Redis redis, String query, int limit) { |
|
|
|
public SimpleDataModel build(Redis redis, String query, int limit) { |
|
|
|
scriptEngine.put("console", new Console()); |
|
|
|
scriptEngine.put("console", new Console()); |
|
|
|
|
|
|
|
scriptEngine.put("Files", new NashornFiles(scriptEngine)); |
|
|
|
scriptEngine.put("redis", new RedisNashornClient(redis.getClient())); |
|
|
|
scriptEngine.put("redis", new RedisNashornClient(redis.getClient())); |
|
|
|
try { |
|
|
|
try { |
|
|
|
scriptEngine.eval(PREPARE_SCRIPT); |
|
|
|
scriptEngine.eval(PREPARE_SCRIPT); |
|
|
@ -135,12 +136,12 @@ public class RedisNashornClient extends BaseRedisClient<Object[], Map<Object, Ob |
|
|
|
|
|
|
|
|
|
|
|
Object el = entry.getValue(); |
|
|
|
Object el = entry.getValue(); |
|
|
|
if (el instanceof Map) { |
|
|
|
if (el instanceof Map) { |
|
|
|
Map<String, Object> rowCollection = (Map<String, Object>)entry.getValue(); |
|
|
|
Map<String, Object> rowCollection = (Map<String, Object>) entry.getValue(); |
|
|
|
for (Map.Entry<String, Object> rowEntry : rowCollection.entrySet()) { |
|
|
|
for (Map.Entry<String, Object> rowEntry : rowCollection.entrySet()) { |
|
|
|
row.add(rowEntry.getValue()); |
|
|
|
row.add(rowEntry.getValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (el instanceof Object[]) { |
|
|
|
} else if (el instanceof Object[]) { |
|
|
|
Object[] array = (Object[])el; |
|
|
|
Object[] array = (Object[]) el; |
|
|
|
row.addAll(Arrays.asList(array)); |
|
|
|
row.addAll(Arrays.asList(array)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -157,7 +158,7 @@ public class RedisNashornClient extends BaseRedisClient<Object[], Map<Object, Ob |
|
|
|
private static ScriptEngine findScriptEngine() { |
|
|
|
private static ScriptEngine findScriptEngine() { |
|
|
|
ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); |
|
|
|
ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); |
|
|
|
ScriptEngine engine = scriptEngineManager.getEngineByName("nashorn"); |
|
|
|
ScriptEngine engine = scriptEngineManager.getEngineByName("nashorn"); |
|
|
|
if(engine == null) { |
|
|
|
if (engine == null) { |
|
|
|
List<ScriptEngineFactory> factories = scriptEngineManager.getEngineFactories(); |
|
|
|
List<ScriptEngineFactory> factories = scriptEngineManager.getEngineFactories(); |
|
|
|
for (ScriptEngineFactory factory : factories) { |
|
|
|
for (ScriptEngineFactory factory : factories) { |
|
|
|
ScriptEngine current = factory.getScriptEngine(); |
|
|
|
ScriptEngine current = factory.getScriptEngine(); |
|
|
|