com.redis.spring.batch.writer.operation.Xadd Maven / Gradle / Ivy
The newest version!
package com.redis.spring.batch.writer.operation;
import java.util.Map;
import java.util.function.Function;
import org.springframework.batch.item.Chunk;
import org.springframework.util.CollectionUtils;
import io.lettuce.core.RedisFuture;
import io.lettuce.core.XAddArgs;
import io.lettuce.core.api.async.BaseRedisAsyncCommands;
import io.lettuce.core.api.async.RedisStreamAsyncCommands;
public class Xadd extends AbstractKeyWriteOperation {
private final Function> bodyFunction;
private Function argsFunction = t -> null;
public Xadd(Function keyFunction, Function> bodyFunction) {
super(keyFunction);
this.bodyFunction = bodyFunction;
}
public void setArgs(XAddArgs args) {
this.argsFunction = t -> args;
}
public void setArgsFunction(Function function) {
this.argsFunction = function;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected void execute(BaseRedisAsyncCommands commands, T item, K key, Chunk> outputs) {
Map map = bodyFunction.apply(item);
if (!CollectionUtils.isEmpty(map)) {
XAddArgs args = argsFunction.apply(item);
outputs.add((RedisFuture) ((RedisStreamAsyncCommands) commands).xadd(key, args, map));
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy