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

com.redis.spring.batch.writer.AbstractKeyValueOperation Maven / Gradle / Ivy

package com.redis.spring.batch.writer;

import java.util.List;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.Predicate;

import io.lettuce.core.RedisFuture;
import io.lettuce.core.api.async.BaseRedisAsyncCommands;

public abstract class AbstractKeyValueOperation extends AbstractKeyOperation {

	private final Function valueFunction;
	private final Predicate skipPredicate;

	protected AbstractKeyValueOperation(Function keyFunction, Function valueFunction) {
		this(keyFunction, valueFunction, Objects::isNull);
	}

	protected AbstractKeyValueOperation(Function keyFunction, Function valueFunction,
			Predicate skipPredicate) {
		super(keyFunction);
		this.skipPredicate = skipPredicate;
		this.valueFunction = valueFunction;
	}

	@SuppressWarnings("unchecked")
	@Override
	protected void execute(BaseRedisAsyncCommands commands, I item, K key, List> outputs) {
		T value = valueFunction.apply(item);
		if (skipPredicate.test(value)) {
			return;
		}
		outputs.add(execute(commands, item, key, value));
	}

	@SuppressWarnings("rawtypes")
	protected abstract RedisFuture execute(BaseRedisAsyncCommands commands, I item, K key, T value);

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy