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

com.redis.spring.batch.writer.operation.Zadd 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.ScoredValue;
import io.lettuce.core.ZAddArgs;
import io.lettuce.core.api.async.BaseRedisAsyncCommands;
import io.lettuce.core.api.async.RedisSortedSetAsyncCommands;

public class Zadd extends AbstractKeyWriteOperation {

	private final Function> valueFunction;
	private Function argsFunction = t -> null;

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

	public void setArgs(ZAddArgs 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) {
		ZAddArgs args = argsFunction.apply(item);
		ScoredValue value = valueFunction.apply(item);
		outputs.add((RedisFuture) ((RedisSortedSetAsyncCommands) commands).zadd(key, args, value));
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy