com.redis.spring.batch.reader.StructPostOperator Maven / Gradle / Ivy
The newest version!
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.common.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 StructPostOperator implements UnaryOperator> {
private final Function toStringValueFunction;
public StructPostOperator(RedisCodec codec) {
this.toStringValueFunction = CodecUtils.toStringValueFunction(codec);
}
@Override
public KeyValue apply(KeyValue t) {
if (t != null) {
t.setValue(value(t));
}
return t;
}
private Object value(KeyValue t) {
if (t.getValue() == null) {
return null;
}
switch (t.getType()) {
case HASH:
return map(t);
case SET:
return set(t);
case ZSET:
return zset(t);
case STREAM:
return stream(t);
case TIMESERIES:
return timeSeries(t);
default:
return t.getValue();
}
}
@SuppressWarnings("unchecked")
private HashSet set(KeyValue t) {
return new HashSet<>((List) t.getValue());
}
@SuppressWarnings("unchecked")
private List timeSeries(KeyValue t) {
List samples = new ArrayList<>();
for (List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy