Skip to content

Commit

Permalink
Showing 17 changed files with 65 additions and 68 deletions.
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -6,6 +6,11 @@ plugins {
id 'org.jreleaser' version '0.2.0'
}

repositories {
mavenLocal()
mavenCentral()
}

asciidoctor {
sourceDir 'docs'
resources {
1 change: 0 additions & 1 deletion buildSrc/src/main/groovy/riot.connector-conventions.gradle
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ plugins {
}

repositories {
mavenLocal()
mavenCentral()
}

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.redislabs.riot;

import com.redislabs.riot.redis.*;
import lombok.Getter;
import lombok.Setter;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.batch.core.step.builder.AbstractTaskletStepBuilder;
import org.springframework.batch.core.step.builder.SimpleStepBuilder;
import org.springframework.batch.core.step.builder.StepBuilder;
@@ -20,14 +20,14 @@
import java.util.function.Function;
import java.util.stream.Collectors;

@Data
@EqualsAndHashCode(callSuper = true)
@Command(subcommands = {EvalCommand.class, ExpireCommand.class, GeoaddCommand.class, HsetCommand.class, LpushCommand.class, NoopCommand.class, RpushCommand.class, SaddCommand.class, SetCommand.class, XaddCommand.class, ZaddCommand.class, SugaddCommand.class}, subcommandsRepeatable = true, synopsisSubcommandLabel = "[REDIS COMMAND]", commandListHeading = "Redis commands:%n")
public abstract class AbstractImportCommand<I, O> extends AbstractTransferCommand {

/**
* Initialized manually during command parsing
*/
@Setter
@Getter
private List<RedisCommand<O>> redisCommands = new ArrayList<>();

protected AbstractTaskletStepBuilder<SimpleStepBuilder<I, O>> step(StepBuilder stepBuilder, String taskName, ItemReader<I> reader) throws Exception {
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.redislabs.riot;

import lombok.Getter;
import lombok.Setter;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.*;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
@@ -18,11 +18,11 @@
import java.util.function.Function;

@Slf4j
@Data
@EqualsAndHashCode(callSuper = true)
@CommandLine.Command
public abstract class AbstractTaskCommand extends RiotCommand {

@Setter
@Getter
private ExecutionStrategy executionStrategy = ExecutionStrategy.SYNC;

protected final Flow flow(Step... steps) {
8 changes: 2 additions & 6 deletions core/src/main/java/com/redislabs/riot/HelpCommand.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package com.redislabs.riot;

import lombok.Getter;
import lombok.Setter;
import lombok.Data;
import picocli.CommandLine;

import java.util.concurrent.Callable;

@Data
@CommandLine.Command(usageHelpAutoWidth = true)
public class HelpCommand {

@SuppressWarnings("unused")
@Setter
@Getter
@CommandLine.Option(names = {"-H", "--help"}, usageHelp = true, description = "Show this help message and exit")
private boolean helpRequested;

2 changes: 2 additions & 0 deletions core/src/main/java/com/redislabs/riot/RiotApp.java
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
import io.netty.util.internal.logging.InternalLoggerFactory;
import io.netty.util.internal.logging.JdkLoggerFactory;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.expression.Expression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import picocli.CommandLine;
@@ -18,6 +19,7 @@
import java.util.logging.Logger;

@Data
@EqualsAndHashCode(callSuper = true)
@Command(sortOptions = false, versionProvider = ManifestVersionProvider.class, subcommands = GenerateCompletionCommand.class, abbreviateSynopsis = true)
public class RiotApp extends HelpCommand {

10 changes: 5 additions & 5 deletions core/src/main/java/com/redislabs/riot/RiotCommand.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package com.redislabs.riot;

import io.lettuce.core.RedisURI;
import lombok.Getter;
import lombok.Setter;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
import picocli.CommandLine.Command;
import picocli.CommandLine.ParentCommand;

import java.util.concurrent.Callable;

@Slf4j
@Data
@EqualsAndHashCode(callSuper = true)
@Command(abbreviateSynopsis = true, sortOptions = false)
public abstract class RiotCommand extends HelpCommand implements Callable<Integer> {

@SuppressWarnings("unused")
@ParentCommand
@Setter
@Getter
public RiotApp app;
private RiotApp app;

protected RedisOptions getRedisOptions() {
return app.getRedisOptions();
1 change: 0 additions & 1 deletion core/src/main/java/com/redislabs/riot/RiotCommandLine.java
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@

public class RiotCommandLine extends CommandLine {

@Getter
private final RiotApp app;
private final IExecutionStrategy executionStrategy;

2 changes: 1 addition & 1 deletion core/src/main/java/com/redislabs/riot/RiotStepBuilder.java
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ public RiotStepBuilder(StepBuilder stepBuilder, TransferOptions options) {
this.options = options;
}

@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "rawtypes"})
public SimpleStepBuilder<I, O> build() {
SimpleStepBuilder<I, O> step = stepBuilder.<I, O>chunk(options.getChunkSize()).reader(reader).processor(processor).writer(writer);
if (options.getProgress() != TransferOptions.Progress.NONE) {
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
package com.redislabs.riot.convert;

import lombok.Setter;
import lombok.Builder;
import org.springframework.core.convert.converter.Converter;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

public class CollectionToStringMapConverter<S extends Collection<String>> implements Converter<S, Map<String, String>> {
@Builder
public class CollectionToStringMapConverter implements Converter<Collection<String>, Map<String, String>> {

public static final String DEFAULT_KEY_FORMAT = "[%s]";
public static final String DEFAULT_KEY_FORMAT = "[%s]";

@Setter
private String keyFormat = DEFAULT_KEY_FORMAT;
@Builder.Default
private final String keyFormat = DEFAULT_KEY_FORMAT;

@Override
public Map<String, String> convert(S source) {
Map<String, String> result = new HashMap<>();
int index = 0;
for (String element : source) {
result.put(String.format(keyFormat, index), element);
index++;
}
return result;
}
@Override
public Map<String, String> convert(Collection<String> source) {
Map<String, String> result = new HashMap<>();
int index = 0;
for (String element : source) {
result.put(String.format(keyFormat, index), element);
index++;
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -26,8 +26,8 @@ public static FieldExtractorBuilder builder() {
return new FieldExtractorBuilder();
}

@Accessors(fluent = true)
@Setter
@Accessors(fluent = true)
public static class FieldExtractorBuilder {

private String field;
Original file line number Diff line number Diff line change
@@ -2,19 +2,19 @@

import io.lettuce.core.StreamMessage;
import lombok.Builder;
import lombok.Setter;
import org.springframework.core.convert.converter.Converter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Builder
public class StreamToStringMapConverter implements Converter<List<StreamMessage<String, String>>, Map<String, String>> {

public static final String DEFAULT_KEY_FORMAT = "%s.%s";

@Setter
private String keyFormat = DEFAULT_KEY_FORMAT;
@Builder.Default
private final String keyFormat = DEFAULT_KEY_FORMAT;

@Override
public Map<String, String> convert(List<StreamMessage<String, String>> source) {
Original file line number Diff line number Diff line change
@@ -10,23 +10,20 @@
import org.springframework.core.convert.converter.Converter;
import org.springframework.util.Assert;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;

public class DataStructureItemProcessor implements ItemProcessor<DataStructure<String>, Map<String, Object>> {

private final Converter<String, Map<String, String>> keyFieldsExtractor;
private final Converter<Map<String, String>, Map<String, String>> hashConverter;
private final Converter<List<StreamMessage<String, String>>, Map<String, String>> streamConverter;
private final Converter<List<String>, Map<String, String>> listConverter;
private final Converter<Set<String>, Map<String, String>> setConverter;
private final Converter<Collection<String>, Map<String, String>> listConverter;
private final Converter<Collection<String>, Map<String, String>> setConverter;
private final Converter<List<ScoredValue<String>>, Map<String, String>> zsetConverter;
private final Converter<String, Map<String, String>> stringConverter;
private final Converter<Object, Map<String, String>> defaultConverter;

public DataStructureItemProcessor(Converter<String, Map<String, String>> keyFieldsExtractor, Converter<Map<String, String>, Map<String, String>> hashConverter, Converter<List<String>, Map<String, String>> listConverter, Converter<Set<String>, Map<String, String>> setConverter, Converter<List<StreamMessage<String, String>>, Map<String, String>> streamConverter, Converter<String, Map<String, String>> stringConverter, Converter<List<ScoredValue<String>>, Map<String, String>> zsetConverter, Converter<Object, Map<String, String>> defaultConverter) {
public DataStructureItemProcessor(Converter<String, Map<String, String>> keyFieldsExtractor, Converter<Map<String, String>, Map<String, String>> hashConverter, Converter<Collection<String>, Map<String, String>> listConverter, Converter<Collection<String>, Map<String, String>> setConverter, Converter<List<StreamMessage<String, String>>, Map<String, String>> streamConverter, Converter<String, Map<String, String>> stringConverter, Converter<List<ScoredValue<String>>, Map<String, String>> zsetConverter, Converter<Object, Map<String, String>> defaultConverter) {
this.keyFieldsExtractor = keyFieldsExtractor;
this.hashConverter = hashConverter;
this.listConverter = listConverter;
@@ -81,18 +78,18 @@ public static DataStructureItemProcessorBuilder builder() {
return new DataStructureItemProcessorBuilder();
}

@Accessors(fluent = true)
@Setter
@Accessors(fluent = true)
public static class DataStructureItemProcessorBuilder {

private String keyRegex;

public DataStructureItemProcessor build() {
Assert.notNull(keyRegex, "Key regex is required.");
RegexNamedGroupsExtractor keyFieldsExtractor = RegexNamedGroupsExtractor.builder().regex(keyRegex).build();
StreamToStringMapConverter streamConverter = new StreamToStringMapConverter();
CollectionToStringMapConverter<List<String>> listConverter = new CollectionToStringMapConverter<>();
CollectionToStringMapConverter<Set<String>> setConverter = new CollectionToStringMapConverter<>();
StreamToStringMapConverter streamConverter = StreamToStringMapConverter.builder().build();
CollectionToStringMapConverter listConverter = CollectionToStringMapConverter.builder().build();
CollectionToStringMapConverter setConverter = CollectionToStringMapConverter.builder().build();
ZsetToStringMapConverter zsetConverter = new ZsetToStringMapConverter();
Converter<String, Map<String, String>> stringConverter = new StringToStringMapConverter();
return new DataStructureItemProcessor(keyFieldsExtractor, c -> c, listConverter, setConverter, streamConverter, stringConverter, zsetConverter, c -> null);
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.redislabs.riot.redis;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.springframework.batch.item.redis.support.operation.AbstractKeyOperation;
@@ -8,15 +10,13 @@

import java.util.Map;

@Data
@EqualsAndHashCode(callSuper = true)
@CommandLine.Command
public abstract class AbstractKeyCommand extends AbstractRedisCommand<Map<String, Object>> {

@Setter
@Getter
@Option(names = {"-p", "--keyspace"}, description = "Keyspace prefix", paramLabel = "<str>")
private String keyspace = "";
@Setter
@Getter
@Option(names = {"-k", "--keys"}, arity = "1..*", description = "Key fields", paramLabel = "<fields>")
private String[] keys;

Original file line number Diff line number Diff line change
@@ -6,25 +6,23 @@
import com.redislabs.riot.convert.FieldExtractor;
import com.redislabs.riot.convert.ObjectToNumberConverter;
import com.redislabs.riot.convert.ObjectToStringConverter;
import lombok.Getter;
import lombok.Setter;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.batch.item.redis.support.KeyMaker;
import org.springframework.core.convert.converter.Converter;
import org.springframework.util.ObjectUtils;
import picocli.CommandLine;

import java.util.Map;

@Data
@EqualsAndHashCode(callSuper = true)
@CommandLine.Command(sortOptions = false, abbreviateSynopsis = true)
public abstract class AbstractRedisCommand<O> extends HelpCommand implements RedisCommand<O> {

@Setter
@Getter
@CommandLine.Option(names = {"-s", "--separator"}, description = "Key separator (default: ${DEFAULT-VALUE})", paramLabel = "<str>")
private String keySeparator = ":";
@SuppressWarnings("unused")
@Setter
@Getter
@CommandLine.Option(names = {"-r", "--remove"}, description = "Remove key or member fields the first time they are used")
private boolean removeFields;

8 changes: 4 additions & 4 deletions core/src/main/java/com/redislabs/riot/redis/HsetCommand.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.redislabs.riot.redis;

import lombok.Getter;
import lombok.Setter;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.batch.item.redis.RedisOperation;
import picocli.CommandLine;
import picocli.CommandLine.Command;

import java.util.Map;

@Data
@EqualsAndHashCode(callSuper = true)
@Command(name = "hset", aliases = "hmset", description = "Set hashes from input")
public class HsetCommand extends AbstractKeyCommand {

@Setter
@Getter
@CommandLine.Mixin
private FilteringOptions filtering = new FilteringOptions();

4 changes: 2 additions & 2 deletions test/src/main/java/com/redislabs/riot/AbstractRiotTest.java
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
import java.nio.charset.Charset;
import java.util.function.Consumer;

@SuppressWarnings("unchecked")
public abstract class AbstractRiotTest {

protected abstract RiotApp app();
@@ -26,8 +27,7 @@ protected String[] args(String filename) throws Exception {
}
}

protected int
execute(String filename, RedisContainer container, Consumer<CommandLine.ParseResult>... configurators) throws Exception {
protected int execute(String filename, RedisContainer container, Consumer<CommandLine.ParseResult>... configurators) throws Exception {
RiotApp app = app();
RiotCommandLine commandLine = app.commandLine();
CommandLine.ParseResult parseResult = commandLine.parseArgs(args(filename));

0 comments on commit e472cc7

Please sign in to comment.