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

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

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

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

import io.lettuce.core.RedisFuture;
import io.lettuce.core.ScoredValue;
import io.lettuce.core.ZAddArgs;
import io.lettuce.core.api.async.BaseRedisAsyncCommands;
import io.lettuce.core.api.async.RedisSortedSetAsyncCommands;

public class ZaddAll extends AbstractOperation {

    private Function>> values;

    private ZAddArgs args;

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

    public void setValues(Function>> values) {
        this.values = values;
    }

    @SuppressWarnings("unchecked")
    @Override
    public void execute(BaseRedisAsyncCommands commands, T item, List> futures) {
        Collection> collection = values(item);
        if (!collection.isEmpty()) {
            futures.add(((RedisSortedSetAsyncCommands) commands).zadd(key(item), args,
                    collection.toArray(new ScoredValue[0])));
        }
    }

    private Collection> values(T item) {
        return values.apply(item);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy