1、匹配方法
redis的key匹配方法有:
//1、
keys
//2、
ScanOptions options = ScanOptions.scanOptions().match("vehicleV2:*").count(1000)
.build();
Cursor<String> cursor = (Cursor<String>) redisTemplate.executeWithStickyConnection(
redisConnection -> new ConvertingCursor<>(redisConnection.scan(options),
redisTemplate.getKeySerializer()::deserialize));
cursor.forEachRemaining(key -> {
log.info("{},长度:{}",key,key.length());
});
//切记这里一定要关闭,否则会耗尽连接数。报Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisException: Could not get a
cursor.close();
2、匹配规则
KEYS pattern
查找所有符合给定模式 pattern 的 key 。
KEYS * 匹配数据库中所有 key 。
KEYS h?llo 匹配 hello , hallo 和 hxllo 等。
KEYS h*llo 匹配 hllo 和 heeeeello 等。
KEYS h[ae]llo 匹配 hello 和 hallo ,但不匹配 hillo 。
特殊符号用 \ 隔开