
io.lettuce.core.output.GenericMapOutput Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lettuce-core Show documentation
Show all versions of lettuce-core Show documentation
Advanced and thread-safe Java Redis client for synchronous, asynchronous, and
reactive usage. Supports Cluster, Sentinel, Pipelining, Auto-Reconnect, Codecs
and much more.
The newest version!
package io.lettuce.core.output;
import java.nio.ByteBuffer;
import java.util.LinkedHashMap;
import java.util.Map;
import io.lettuce.core.codec.RedisCodec;
/**
* {@link Map} of keys and objects output.
*
* @param Key type.
* @param Value type.
*
* @author Mark Paluch
* @since 6.0/RESP3
*/
public class GenericMapOutput extends CommandOutput> {
boolean hasKey;
private K key;
public GenericMapOutput(RedisCodec codec) {
super(codec, null);
}
@Override
public void set(ByteBuffer bytes) {
if (!hasKey) {
key = (bytes == null) ? null : codec.decodeKey(bytes);
hasKey = true;
return;
}
Object value = (bytes == null) ? null : codec.decodeValue(bytes);
output.put(key, value);
key = null;
hasKey = false;
}
@Override
public void setBigNumber(ByteBuffer bytes) {
set(bytes);
}
@Override
@SuppressWarnings("unchecked")
public void set(long integer) {
if (!hasKey) {
key = (K) Long.valueOf(integer);
hasKey = true;
return;
}
V value = (V) Long.valueOf(integer);
output.put(key, value);
key = null;
hasKey = false;
}
@Override
public void set(double number) {
if (!hasKey) {
key = (K) Double.valueOf(number);
hasKey = true;
return;
}
Object value = Double.valueOf(number);
output.put(key, value);
key = null;
hasKey = false;
}
@Override
public void multi(int count) {
if (output == null) {
output = new LinkedHashMap<>(count / 2, 1);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy