spring 批量获取redis String、set类型的键列(模糊匹配)

String pattern="Team:*"
Integer perCount = 1000;
List keys = Lists.newArrayList();
redisTemplate.execute((RedisConnection connection) -> {
    try (Cursor cursor = connection.scan(ScanOptions.scanOptions().count(perCount).match(pattern).build())) {
        while (cursor.hasNext()){
            String key = new String(cursor.next(), StandardCharsets.UTF_8);
            keys.add(key);

            //do yourthing

     }catch (IOException e) {
            throw new RuntimeException(e);
     }

 

你可能感兴趣的:(redis)