2022年10月31日 作者 zeroheart

redisTemplate使用scan

public Set scan(String pattern) {
        Set<String> keySet = (Set) redisTemplate.execute((RedisCallback<Set<String>>) connection -> {
            Set<String> keysTemp = new HashSet<>();
            Cursor<byte[]> cursor = connection.scan(ScanOptions.scanOptions().match(pattern).count(10000).build());
            while (cursor.hasNext()) {
                keysTemp.add(new String(cursor.next()));
            }
            return keysTemp;
        });
        logger.info("tokenSize:{}, keys:{}", keySet.size(), JSONUtil.toJsonStr(keySet));
        return keySet;
    }


原文链接:https://blog.csdn.net/rui15111/article/details/125636103