forked from fanruan/demo-tabledata-redis
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.4 KiB
52 lines
1.4 KiB
package com.fr.plugin.db.redis.util; |
|
|
|
import com.eclipsesource.v8.V8Object; |
|
import com.fr.stable.ParameterProvider; |
|
import com.fanruan.api.util.RenderKit; |
|
import com.fr.plugin.db.redis.help.ScriptBridge; |
|
import com.fanruan.api.util.ArrayKit; |
|
import com.fr.third.redis.clients.jedis.Jedis; |
|
|
|
import java.lang.reflect.Method; |
|
import java.util.HashMap; |
|
import java.util.Map; |
|
|
|
/** |
|
* @author richie |
|
* @version 10.0 |
|
* Created by richie on 2019-03-18 |
|
*/ |
|
public class RedisUtils { |
|
|
|
/** |
|
* 关闭redis客户端 |
|
* @param jedis redis客户端对象 |
|
*/ |
|
public static void close(Jedis jedis) { |
|
jedis.close(); |
|
} |
|
|
|
public static String calculateQuery(String query, Parameter[] ps) { |
|
if (ArrayKit.isEmpty(ps)) { |
|
return query; |
|
} |
|
Map<String, Object> map = new HashMap<String, Object>(); |
|
for (Parameter p : ps) { |
|
map.put(p.getName(), p.getValue()); |
|
} |
|
try { |
|
return RenderKit.renderParameter4Tpl(query, map); |
|
} catch (Exception e) { |
|
return query; |
|
} |
|
} |
|
|
|
public static void registerJavaMethods(V8Object v8Object, Object target) { |
|
Method[] methods = target.getClass().getMethods(); |
|
for (Method m : methods) { |
|
if (m.getAnnotation(ScriptBridge.class) != null) { |
|
v8Object.registerJavaMethod(target, m.getName(), m.getName(), m.getParameterTypes()); |
|
} |
|
} |
|
} |
|
}
|
|
|