Commit c7299531 authored by lizhiheng's avatar lizhiheng

feat:新增luaAdd方法,把BF.ADD命令通过lua的形式去执行

parent a4d5a4f5
......@@ -38,7 +38,7 @@ allprojects {
}
group = "cn.com.duiba.boot"
version = "0.0.49"
version = "0.0.50"
}
subprojects {
......
......@@ -243,6 +243,26 @@ public class RedisBloomHandler<K, V> {
return null;
}
/**
* 添加到bloom
* 添加该方法是为了兼容lettuce客户端,lettuce会进行命令校验
* 其枚举值类:{CommandType}中没有BF.ADD或者BF.MEXISTS等方法,只能通过直接写在lua中,绕过命令校验
* @param key redis key
* @param value 值
* @return
*/
public Integer luaAdd(String key, String value) {
String luaText = "if (redis.call('BF.ADD',KEYS[1],ARGV[1]))==1 then return 1 else return 0 end";
DefaultRedisScript<Long> redisScript = new DefaultRedisScript<>();
redisScript.setScriptSource(new StaticScriptSource(luaText));
redisScript.setResultType(Long.class);
Object execute = redisTemplate.execute(redisScript, Collections.singletonList(key), value);
if (NumberUtils.isNumeric(execute + "")) {
return Integer.valueOf(execute + "");
}
return null;
}
/**
* 判断创建redis 布隆过滤器
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment