com.redis.spring.batch.writer.operation.Sugadd Maven / Gradle / Ivy
package com.redis.spring.batch.writer.operation;
import java.util.List;
import java.util.function.Function;
import com.redis.lettucemod.api.async.RediSearchAsyncCommands;
import com.redis.lettucemod.search.Suggestion;
import io.lettuce.core.RedisFuture;
import io.lettuce.core.api.async.BaseRedisAsyncCommands;
public class Sugadd extends AbstractOperation {
private Function> suggestion;
private boolean incr;
public void setSuggestion(Function> suggestion) {
this.suggestion = suggestion;
}
public void setIncr(boolean incr) {
this.incr = incr;
}
@SuppressWarnings("unchecked")
@Override
public void execute(BaseRedisAsyncCommands commands, T item, List> futures) {
futures.add(execute((RediSearchAsyncCommands) commands, key(item), suggestion(item)));
}
private Suggestion suggestion(T item) {
return suggestion.apply(item);
}
private RedisFuture execute(RediSearchAsyncCommands commands, K key, Suggestion suggestion) {
if (incr) {
return commands.ftSugaddIncr(key, suggestion);
}
return commands.ftSugadd(key, suggestion);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy