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

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

The newest version!
package com.redis.spring.batch.writer.operation;

import java.util.Collection;
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.api.async.BaseRedisAsyncCommands;
import io.lettuce.core.api.async.RedisSetAsyncCommands;

public class SaddAll extends AbstractKeyWriteOperation {

	private final Function> valuesFunction;

	protected SaddAll(Function keyFunction, Function> valuesFunction) {
		super(keyFunction);
		this.valuesFunction = valuesFunction;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	protected void execute(BaseRedisAsyncCommands commands, T item, K key, Chunk> outputs) {
		Collection collection = valuesFunction.apply(item);
		if (!CollectionUtils.isEmpty(collection)) {
			outputs.add((RedisFuture) ((RedisSetAsyncCommands) commands).sadd(key, (V[]) collection.toArray()));
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy