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

com.redis.spring.batch.writer.operation.Set 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.SetArgs;
import io.lettuce.core.api.async.BaseRedisAsyncCommands;
import io.lettuce.core.api.async.RedisStringAsyncCommands;

public class Set extends AbstractKeyWriteOperation {

	private static final SetArgs DEFAULT_ARGS = new SetArgs();

	private final Function valueFunction;

	private Function argsFunction = t -> DEFAULT_ARGS;

	public Set(Function keyFunction, Function valueFunction) {
		super(keyFunction);
		this.valueFunction = valueFunction;
	}

	public void setArgs(SetArgs args) {
		this.argsFunction = t -> args;
	}

	public void setArgsFunction(Function function) {
		this.argsFunction = function;
	}

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

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy