Commit e9628ed1 authored by lizhiheng's avatar lizhiheng

feat:新增saveBloom的相关方法,用于查看这次是第几次请求

parent f17bb6ac
......@@ -38,7 +38,7 @@ allprojects {
}
group = "cn.com.duiba.boot"
version = "0.0.56"
version = "0.0.57"
}
subprojects {
......
......@@ -243,6 +243,34 @@ public class RedisBloomHandler<K, V> {
return null;
}
/**
* 配合saveBloom一起使用
* 查看这是第几次请求
*
* @param key redis key
* @param value 值
* @param levelCount 过滤总层次
* @return
*/
public Integer checkBloomTimes(String key, String value, Integer levelCount) {
String luaText = "local a = " + (levelCount + 1) + "\n" +
"for i = 1," + (levelCount) + 1 + ",1 do\n" +
" if(redis.call('BF.EXISTS', KEYS[1], (ARGV[1] .. '_' .. i)) == 0) then\n" +
" a = i;\n" +
" break;\n" +
" end\n" +
"end\n" +
"return a;";
DefaultRedisScript<Long> redisScript = new DefaultRedisScript<>();
redisScript.setScriptSource(new StaticScriptSource(luaText));
redisScript.setResultType(Long.class);
Object execute = redisTemplate.execute(redisScript, Collections.singletonList(key), value, String.valueOf(levelCount));
if (NumberUtils.isNumeric(execute + "")) {
return Integer.valueOf(execute + "");
}
return null;
}
/**
* 添加到bloom
* 添加该方法是为了兼容lettuce客户端,lettuce会进行命令校验
......@@ -268,6 +296,7 @@ public class RedisBloomHandler<K, V> {
/**
* 自助接口,传入需要使用到的redis实例、lua表达式、key和value
* 需要注意的是,这个方法返回类型是Object,需要下游强转,使用前请先先本地lua调试
*
* @param redisTemplate 使用到到redis实例
* @param luaText 传入到lua脚本
* @param key
......
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