diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/redis/RedisItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/redis/RedisItemReader.java index f5142fa39a..540f724595 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/redis/RedisItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/redis/RedisItemReader.java @@ -37,40 +37,48 @@ * @param type of keys * @param type of values */ -public class RedisItemReader implements ItemStreamReader { +public class RedisItemReader implements ItemStreamReader { - private final RedisTemplate redisTemplate; + public static class KeyValue { - private final ScanOptions scanOptions; + K key; + V value; - private Cursor cursor; + KeyValue(K key, V value) { + this.key = key; + this.value = value; + } + } - public RedisItemReader(RedisTemplate redisTemplate, ScanOptions scanOptions) { - Assert.notNull(redisTemplate, "redisTemplate must not be null"); - Assert.notNull(scanOptions, "scanOptions must no be null"); - this.redisTemplate = redisTemplate; - this.scanOptions = scanOptions; - } + private final RedisTemplate redisTemplate; - @Override - public void open(ExecutionContext executionContext) throws ItemStreamException { - this.cursor = this.redisTemplate.scan(this.scanOptions); - } + private final ScanOptions scanOptions; - @Override - public V read() throws Exception { - if (this.cursor.hasNext()) { - K nextKey = this.cursor.next(); - return this.redisTemplate.opsForValue().get(nextKey); - } - else { - return null; - } - } + private Cursor cursor; - @Override - public void close() throws ItemStreamException { - this.cursor.close(); - } + public RedisItemReader(RedisTemplate redisTemplate, ScanOptions scanOptions) { + Assert.notNull(redisTemplate, "redisTemplate must not be null"); + Assert.notNull(scanOptions, "scanOptions must no be null"); + this.redisTemplate = redisTemplate; + this.scanOptions = scanOptions; + } + @Override + public void open(ExecutionContext executionContext) throws ItemStreamException { + this.cursor = this.redisTemplate.scan(this.scanOptions); + } + + @Override + public K read() throws Exception { + if (this.cursor.hasNext()) { + return this.cursor.next(); + } else { + return null; + } + } + + @Override + public void close() throws ItemStreamException { + this.cursor.close(); + } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/redis/RedisItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/redis/RedisItemWriter.java index c9b0ae3ee3..d8aea50c2d 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/redis/RedisItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/redis/RedisItemWriter.java @@ -30,16 +30,15 @@ * @author Mahmoud Ben Hassine * @since 5.1 */ -public class RedisItemWriter extends KeyValueItemWriter { +public class RedisItemWriter extends KeyValueItemWriter { private RedisTemplate redisTemplate; @Override - protected void writeKeyValue(K key, T value) { + protected void writeKeyValue(T value, K key) { if (this.delete) { this.redisTemplate.delete(key); - } - else { + } else { this.redisTemplate.opsForValue().set(key, value); } } @@ -51,10 +50,10 @@ protected void init() { /** * Set the {@link RedisTemplate} to use. + * * @param redisTemplate the template to use */ public void setRedisTemplate(RedisTemplate redisTemplate) { this.redisTemplate = redisTemplate; } - }