com.redis.spring.batch.writer.operation.JsonSet 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.RedisJSONAsyncCommands;
import io.lettuce.core.RedisFuture;
import io.lettuce.core.api.async.BaseRedisAsyncCommands;
public class JsonSet extends AbstractKeyWriteOperation {
public static final String ROOT_PATH = "$";
private final Function valueFunction;
private Function pathFunction = t -> ROOT_PATH;
public JsonSet(Function keyFunction, Function valueFunction) {
super(keyFunction);
this.valueFunction = valueFunction;
}
public void setPath(String path) {
this.pathFunction = t -> path;
}
public void setPathFunction(Function path) {
this.pathFunction = path;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected void execute(BaseRedisAsyncCommands commands, T item, K key, Chunk> outputs) {
String path = pathFunction.apply(item);
V value = valueFunction.apply(item);
outputs.add((RedisFuture) ((RedisJSONAsyncCommands) commands).jsonSet(key, path, value));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy