com.redis.spring.batch.writer.operation.TsAdd 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 com.redis.lettucemod.api.async.RedisTimeSeriesAsyncCommands;
import com.redis.lettucemod.timeseries.AddOptions;
import com.redis.lettucemod.timeseries.Sample;
import io.lettuce.core.RedisFuture;
import io.lettuce.core.api.async.BaseRedisAsyncCommands;
public class TsAdd extends AbstractKeyWriteOperation {
private final Function sampleFunction;
private Function> optionsFunction = t -> null;
public TsAdd(Function keyFunction, Function sampleFunction) {
super(keyFunction);
this.sampleFunction = sampleFunction;
}
public void setOptions(AddOptions options) {
this.optionsFunction = t -> options;
}
public void setOptionsFunction(Function> function) {
this.optionsFunction = function;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void execute(BaseRedisAsyncCommands commands, T item, K key, Chunk> outputs) {
AddOptions options = optionsFunction.apply(item);
Sample sample = sampleFunction.apply(item);
if (sample != null) {
outputs.add((RedisFuture) ((RedisTimeSeriesAsyncCommands) commands).tsAdd(key, sample, options));
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy