/**
* 使用scan正則表達式檢索
*
* @param regex 正則表達式
* @param count 增量迭代
*/
public Set<String> scan(String regex, long count) {
ScanOptions options = ScanOptions.scanOptions()
.match(regex)
.count(count)
.build();
return redisTemplate.execute((RedisCallback<Set<String>>) connection -> {
Set<String> keys = new HashSet<>();
Cursor<byte[]> cursor = connection.scan(options);
while (cursor.hasNext()) {
keys.add(new String(cursor.next()));
}
return keys;
});
}