Search in sources :

Example 1 with ScanCursor

use of com.lambdaworks.redis.ScanCursor in project moleculer-java by moleculer-java.

the class RedisGetSetClient method clean.

private final CompletionStage<Object> clean(RedisFuture<KeyScanCursor<byte[]>> future, ScanArgs args, String match) {
    return future.thenCompose(keyScanCursor -> {
        List<byte[]> keys = keyScanCursor.getKeys();
        if (keys == null || keys.isEmpty()) {
            return CompletableFuture.completedFuture(keyScanCursor);
        }
        if (match != null) {
            Iterator<byte[]> i = keys.iterator();
            while (i.hasNext()) {
                if (!Matcher.matches(new String(i.next(), StandardCharsets.UTF_8), match)) {
                    i.remove();
                }
            }
        }
        if (keys.isEmpty()) {
            return CompletableFuture.completedFuture(keyScanCursor);
        }
        byte[][] array = new byte[keys.size()][];
        keys.toArray(array);
        return client.del(array).thenApply(nul -> keyScanCursor);
    }).thenApply(keyScanCursor -> {
        if (((KeyScanCursor<byte[]>) keyScanCursor).isFinished()) {
            return null;
        }
        return ((KeyScanCursor<byte[]>) keyScanCursor).getCursor();
    }).thenCompose(currentCursor -> {
        if (currentCursor == null) {
            return CompletableFuture.completedFuture(null);
        }
        return clean(new ScanCursor((String) currentCursor, false), args, match);
    });
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) SetArgs(com.lambdaworks.redis.SetArgs) ScanCursor(com.lambdaworks.redis.ScanCursor) ArrayList(java.util.ArrayList) Observable(rx.Observable) KeyScanCursor(com.lambdaworks.redis.KeyScanCursor) RedisFuture(com.lambdaworks.redis.RedisFuture) EventBus(com.lambdaworks.redis.event.EventBus) LinkedList(java.util.LinkedList) DefaultClientResources(com.lambdaworks.redis.resource.DefaultClientResources) Event(com.lambdaworks.redis.event.Event) ExecutorService(java.util.concurrent.ExecutorService) RedisClusterClient(com.lambdaworks.redis.cluster.RedisClusterClient) EventLoopGroup(io.netty.channel.EventLoopGroup) Iterator(java.util.Iterator) ByteArrayCodec(com.lambdaworks.redis.codec.ByteArrayCodec) ScanArgs(com.lambdaworks.redis.ScanArgs) RedisClient(com.lambdaworks.redis.RedisClient) EventExecutorGroup(io.netty.util.concurrent.EventExecutorGroup) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) EventLoopGroupProvider(com.lambdaworks.redis.resource.EventLoopGroupProvider) Promise(services.moleculer.Promise) TimeUnit(java.util.concurrent.TimeUnit) DefaultEventExecutor(io.netty.util.concurrent.DefaultEventExecutor) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Matcher(services.moleculer.eventbus.Matcher) RedisURI(com.lambdaworks.redis.RedisURI) Future(io.netty.util.concurrent.Future) RedisAsyncCommands(com.lambdaworks.redis.api.async.RedisAsyncCommands) RedisAdvancedClusterAsyncCommands(com.lambdaworks.redis.cluster.api.async.RedisAdvancedClusterAsyncCommands) ScanCursor(com.lambdaworks.redis.ScanCursor) KeyScanCursor(com.lambdaworks.redis.KeyScanCursor)

Aggregations

KeyScanCursor (com.lambdaworks.redis.KeyScanCursor)1 RedisClient (com.lambdaworks.redis.RedisClient)1 RedisFuture (com.lambdaworks.redis.RedisFuture)1 RedisURI (com.lambdaworks.redis.RedisURI)1 ScanArgs (com.lambdaworks.redis.ScanArgs)1 ScanCursor (com.lambdaworks.redis.ScanCursor)1 SetArgs (com.lambdaworks.redis.SetArgs)1 RedisAsyncCommands (com.lambdaworks.redis.api.async.RedisAsyncCommands)1 RedisClusterClient (com.lambdaworks.redis.cluster.RedisClusterClient)1 RedisAdvancedClusterAsyncCommands (com.lambdaworks.redis.cluster.api.async.RedisAdvancedClusterAsyncCommands)1 ByteArrayCodec (com.lambdaworks.redis.codec.ByteArrayCodec)1 Event (com.lambdaworks.redis.event.Event)1 EventBus (com.lambdaworks.redis.event.EventBus)1 DefaultClientResources (com.lambdaworks.redis.resource.DefaultClientResources)1 EventLoopGroupProvider (com.lambdaworks.redis.resource.EventLoopGroupProvider)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 DefaultEventExecutor (io.netty.util.concurrent.DefaultEventExecutor)1 EventExecutorGroup (io.netty.util.concurrent.EventExecutorGroup)1 Future (io.netty.util.concurrent.Future)1