All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lambdaworks.redis.output.MapOutput Maven / Gradle / Ivy

There is a newer version: 2.3.3
Show newest version
// Copyright (C) 2011 - Will Glozer.  All rights reserved.

package com.lambdaworks.redis.output;

import com.lambdaworks.redis.codec.RedisCodec;
import com.lambdaworks.redis.protocol.CommandOutput;

import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;

/**
 * {@link Map} of keys and values output.
 *
 * @param  Key type.
 * @param  Value type.
 *
 * @author Will Glozer
 */
public class MapOutput extends CommandOutput> {
    private K key;

    public MapOutput(RedisCodec codec) {
        super(codec, new HashMap());
    }

    @Override
    public void set(ByteBuffer bytes) {
        if (key == null) {
            key = codec.decodeKey(bytes);
            return;
        }

        V value = (bytes == null) ? null : codec.decodeValue(bytes);
        output.put(key, value);
        key = null;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy