@Override
    public long count(final String pattern) {
        val scanOptions = ScanOptions.scanOptions().match(pattern);
        val connection = Objects.requireNonNull(getConnectionFactory()).getConnection();
        val cursor = connection.keyCommands().scan(scanOptions.build());
        return StreamSupport
            .stream(Spliterators.spliteratorUnknownSize(cursor, Spliterator.ORDERED), false)
            .onClose(() -> {
                IOUtils.closeQuietly(cursor);
                connection.close();
            })
            .count();
    }
This is {@link DefaultCasRedisTemplate}.

@author Misagh Moayyed
@since 6.5.0
support/cas-server-support-redis-core/src/main/java/org/apereo/cas/redis/core/DefaultCasRedisTemplate.java