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

com.redis.spring.batch.writer.PushAll Maven / Gradle / Ivy

package com.redis.spring.batch.writer;

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

import org.springframework.util.CollectionUtils;

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

public abstract class PushAll extends AbstractKeyValueOperation, T> {

	protected PushAll(Function keyFunction, Function> valuesFunction) {
		super(keyFunction, valuesFunction, CollectionUtils::isEmpty);
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	protected RedisFuture execute(BaseRedisAsyncCommands commands, T item, K key, Collection value) {
		V[] array = (V[]) value.toArray();
		return doPush((RedisListAsyncCommands) commands, key, array);
	}

	protected abstract RedisFuture doPush(RedisListAsyncCommands commands, K key, V[] values);

}