Commit 8ed6a959 authored by shenjiaqing's avatar shenjiaqing

Merge branch 'feat-newAddMethod' into 'master'

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

See merge request !2
parents a4d5a4f5 c7299531
...@@ -38,7 +38,7 @@ allprojects { ...@@ -38,7 +38,7 @@ allprojects {
} }
group = "cn.com.duiba.boot" group = "cn.com.duiba.boot"
version = "0.0.49" version = "0.0.50"
} }
subprojects { subprojects {
......
...@@ -243,6 +243,26 @@ public class RedisBloomHandler<K, V> { ...@@ -243,6 +243,26 @@ public class RedisBloomHandler<K, V> {
return null; 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 布隆过滤器 * 判断创建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