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

com.redis.spring.batch.writer.operation.Xadd 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.Map;
import java.util.function.Function;

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 AbstractOperation {

    private Function args = t -> null;

    private Function> body;

    public void setArgs(XAddArgs args) {
        setArgs(t -> args);
    }

    public void setArgs(Function args) {
        this.args = args;
    }

    public void setBody(Function> body) {
        this.body = body;
    }

    @SuppressWarnings("unchecked")
    @Override
    public void execute(BaseRedisAsyncCommands commands, T item, List> futures) {
        Map map = body(item);
        if (!map.isEmpty()) {
            futures.add(((RedisStreamAsyncCommands) commands).xadd(key(item), args(item), map));
        }
    }

    private Map body(T item) {
        return body.apply(item);
    }

    private XAddArgs args(T item) {
        return args.apply(item);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy