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

com.redis.spring.batch.writer.operation.AbstractPush Maven / Gradle / Ivy

The newest version!
package com.redis.spring.batch.writer.operation;

import java.util.function.Function;

import org.springframework.batch.item.Chunk;

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

public abstract class AbstractPush extends AbstractKeyWriteOperation {

	protected AbstractPush(Function keyFunction) {
		super(keyFunction);
	}

	private Function valueFunction;

	public void setValueFunction(Function function) {
		this.valueFunction = function;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	protected void execute(BaseRedisAsyncCommands commands, T item, K key, Chunk> outputs) {
		V value = valueFunction.apply(item);
		outputs.add((RedisFuture) doPush((RedisListAsyncCommands) commands, key, value));
	}

	protected abstract RedisFuture doPush(RedisListAsyncCommands commands, K key, V value);

}