All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.batch.item.redis.KeyDumpItemWriter Maven / Gradle / Ivy

There is a newer version: 2.16.0
Show newest version
package org.springframework.batch.item.redis;

import io.lettuce.core.RedisClient;
import io.lettuce.core.api.StatefulConnection;
import io.lettuce.core.api.async.BaseRedisAsyncCommands;
import io.lettuce.core.cluster.RedisClusterClient;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.batch.item.redis.support.CommandBuilder;
import org.springframework.batch.item.redis.support.KeyValue;
import org.springframework.batch.item.redis.support.operation.Restore;

import java.util.function.Function;
import java.util.function.Supplier;

public class KeyDumpItemWriter extends OperationItemWriter> {

    public KeyDumpItemWriter(Supplier> statefulConnectionSupplier, GenericObjectPoolConfig> poolConfig, Function, BaseRedisAsyncCommands> async) {
        super(statefulConnectionSupplier, poolConfig, async, restoreOperation());
    }

    private static RedisOperation> restoreOperation() {
        return new Restore<>(KeyValue::getKey, KeyValue::getValue, KeyValue::getAbsoluteTTL);
    }

    public static KeyDumpItemWriterBuilder client(RedisClient client) {
        return new KeyDumpItemWriterBuilder(client);
    }

    public static KeyDumpItemWriterBuilder client(RedisClusterClient client) {
        return new KeyDumpItemWriterBuilder(client);
    }

    public static class KeyDumpItemWriterBuilder extends CommandBuilder {

        public KeyDumpItemWriterBuilder(RedisClusterClient client) {
            super(client);
        }

        public KeyDumpItemWriterBuilder(RedisClient client) {
            super(client);
        }

        public KeyDumpItemWriter build() {
            return new KeyDumpItemWriter(connectionSupplier, poolConfig, async);
        }

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy