Spring data redis uses the Luttuce client to delete the specified key question

1, background

official Redis cluster clustering scheme currently used by redis:

spring data redis and Luttuce currently used by cli: (luttuce is better than jedis instead of jedis, cluster)

2. Purpose
want to delete some pattern matching key

online because of blocking high-risk commands such as keys, flushdb

so currently use scan to match key and delete them one by one, but when it is actually executed, the exception is reported as follows:

InvalidDataAccessApiUsageException: Scan is not supported across multiple nodes within a cluster

to flip the source code, it is true that cluster does not support direct scan cluster, to ask how to implement it?

when redis is in master-slave mode, it is written like this:

public void flushdb() {
        ScanOptions scanOptions = new ScanOptions.ScanOptionsBuilder().match("user_slash*").count(1000).build();
        redisTemplate.execute((RedisCallback<Object>) connection -> {
            Cursor<byte[]> cursor = connection.scan(scanOptions);
            while (cursor.hasNext()) {
                connection.del(cursor.next());
            }
            return null;
        });
    }
Issues not found on

spring data redis github


get all nodes and use the scan command to read them respectively;
cursor remember that close (), will not release the connection if you finish using it.

Menu