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

com.redis.spring.batch.writer.operation.JsonSet Maven / Gradle / Ivy

There is a newer version: 4.0.7
Show newest version
package com.redis.spring.batch.writer.operation;

import java.util.List;
import java.util.function.Function;

import com.redis.lettucemod.api.async.RedisJSONAsyncCommands;

import io.lettuce.core.RedisFuture;
import io.lettuce.core.api.async.BaseRedisAsyncCommands;

public class JsonSet extends AbstractOperation {

    private Function path = rootPath();

    private Function value;

    public void setPath(String path) {
        setPath(t -> path);
    }

    public void setPath(Function path) {
        this.path = path;
    }

    public void setValue(Function value) {
        this.value = value;
    }

    @SuppressWarnings("unchecked")
    @Override
    public void execute(BaseRedisAsyncCommands commands, T item, List> futures) {
        futures.add(((RedisJSONAsyncCommands) commands).jsonSet(key(item), path(item), value(item)));
    }

    private V value(T item) {
        return value.apply(item);
    }

    private String path(T item) {
        return path.apply(item);
    }

    public static  Function rootPath() {
        return t -> "$";
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy