com.redis.spring.batch.reader.ListToKeyValueStruct Maven / Gradle / Ivy
package com.redis.spring.batch.reader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import com.redis.lettucemod.timeseries.Sample;
import com.redis.spring.batch.KeyValue;
import com.redis.spring.batch.util.CodecUtils;
import io.lettuce.core.ScoredValue;
import io.lettuce.core.StreamMessage;
import io.lettuce.core.codec.RedisCodec;
import io.lettuce.core.internal.LettuceAssert;
public class ListToKeyValueStruct implements UnaryOperator> {
private final Function toStringValueFunction;
public ListToKeyValueStruct(RedisCodec codec) {
this.toStringValueFunction = CodecUtils.toStringValueFunction(codec);
}
@Override
public KeyValue apply(KeyValue item) {
if (item == null || item.getValue() == null) {
return item;
}
switch (item.getType()) {
case KeyValue.HASH:
item.setValue(map(item.getValue()));
break;
case KeyValue.SET:
item.setValue(new HashSet<>(item.getValue()));
break;
case KeyValue.ZSET:
item.setValue(zset(item.getValue()));
break;
case KeyValue.STREAM:
item.setValue(stream(item.getKey(), item.getValue()));
break;
case KeyValue.TIMESERIES:
item.setValue(timeSeries(item.getValue()));
break;
default:
// do nothing
break;
}
return item;
}
@SuppressWarnings("unchecked")
private List timeSeries(List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy