public void hScan(String key,String pattern, Integer member) {
// 1 扫描所有键 * 匹配任意字符 ? 匹配一个字符
redisTemplate.opsForHash().keys(pattern);
// scan 扫描
ScanOptions options = ScanOptions.scanOptions().match("*").count(member).build();
Cursor<Map.Entry<Object, Object>> cursor = redisTemplate.opsForHash().scan("key", options);
while (cursor.hasNext()) {
Map.Entry<Object, Object> entry = cursor.next();
System.out.println("User ID: " + entry.getKey() + ", Name: " + entry.getValue());
}
cursor.close();
}
此博客展示了Java代码中对Redis的Hash进行扫描操作。通过redisTemplate.opsForHash().keys方法扫描所有键,使用ScanOptions构建扫描选项,利用cursor遍历结果并输出键值对,最后关闭cursor。
3万+

被折叠的 条评论
为什么被折叠?



