记录一个查询多个值是否存在的脚本:
- redis脚本
eval
"local result = {}
for i, id in ipairs(ARGV) do
if redis.call('EXISTS', id) == 1 then
table.insert(result, {id, 1})
else
table.insert(result, {id, 0})
end
end
return result" 0 a b c
- java
try (Jedis jedis = jedisPool.getResource()) {
jedis.select(8);
String script = "" +
"local result = {}\n" +
"local keys = ARGV\n" +
"\n" +
"for i, id in ipairs(keys) do\n" +
" if redis.call('EXISTS', id) == 1 then\n" +
" table.insert(result, {id, 1})\n" +
" else \n" +
" table.insert(result, {id, 0})\n" +
" end \n" +
"end \n" +
"\n" +
"return result";
List<List<String>> result = (List) jedis.eval(script, Collections.singletonList(""), Arrays.asList("a","b","c"));
}```
- Jedis自带功能
```java
jedis.scriptExists()
本文由 GY 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为:
2024/03/06 10:50