使用redisTemplate.keys(str),版本问题会报
ERR unknown command KEYS
, with args beginning with: `…
因此可使用
String pattern = "Impl:*";
AtomicInteger count = new AtomicInteger();
List<String> lis = new ArrayList<>();
ScanOptions options = ScanOptions.scanOptions().match(pattern).count(1000)
.build();
Cursor<String> cursor = (Cursor<String>) redisTemplate.executeWithStickyConnection(
redisConnection -> new ConvertingCursor<>(redisConnection.scan(options),
redisTemplate.getKeySerializer()::deserialize));
cursor.forEachRemaining(key -> {
redisTemplate.delete(key);
});
System.out.println(lis.toString());