package org.apereo.cas.redis.core.util;

import lombok.experimental.UtilityClass;
import lombok.val;
import org.apache.commons.io.IOUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ScanOptions;

import java.util.Objects;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

/**
 * This is {@link RedisUtils}.
 *
 * @author Fireborn Z
 * @since 6.5.0
 */
@UtilityClass
public class RedisUtils {
    private static final long SCAN_COUNT = 1000L;

    /**
     * Get redis keys using scan command.
     *
     * @param redisTemplate the redisTemplate
     * @param pattern       the redis keys pattern
     * @return the redis keys
     */
    public static Stream<String> keys(final RedisTemplate<String, ?> redisTemplate, final String pattern) {
        return keys(redisTemplate, pattern, SCAN_COUNT);
    }

    /**
     * Get redis keys using scan command.
     *
     * @param redisTemplate the redisTemplate
     * @param pattern       the redis keys pattern
     * @param count         the scan limit
     * @return the redis keys
     */
    public static Stream<String> keys(final RedisTemplate<String, ?> redisTemplate, final String pattern, final long count) {
        val cursor = Objects.requireNonNull(redisTemplate.getConnectionFactory())
            .getConnection()
            .scan(ScanOptions.scanOptions().match(pattern).count(count).build());
        return StreamSupport
            .stream(Spliterators.spliteratorUnknownSize(cursor, Spliterator.ORDERED), false)
            .onClose(() -> IOUtils.closeQuietly(cursor))
            .map(key -> (String) redisTemplate.getKeySerializer().deserialize(key));
    }
}

@@ -619,32 +619,195 @@
 g scan command.%0A
+     * %3Cp%3E%0A     * This method is similar to %7B@link RedisUtils#keys(RedisTemplate, String, long)%7D,%0A     * with a default COUNT value %7B@link RedisUtils#SCAN_COUNT%7D.%0A
      *%0A     * @p
@@ -1299,12 +1299,12 @@
 can 
-limi
+coun
 t%0A  

update javadoc for RedisUtils.keys