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

io.lettuce.core.output.KeyValueScanStreamingOutput Maven / Gradle / Ivy

Go to download

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 io.lettuce.core.StreamScanCursor;
import io.lettuce.core.codec.RedisCodec;

/**
 * Streaming-Output of Key Value Pairs. Returns the count of all Key-Value pairs (including null).
 *
 * @param  Key type.
 * @param  Value type.
 *
 * @author Mark Paluch
 */
public class KeyValueScanStreamingOutput extends ScanOutput {

    private K key;

    private boolean hasKey;

    private KeyValueStreamingChannel channel;

    public KeyValueScanStreamingOutput(RedisCodec codec, KeyValueStreamingChannel channel) {
        super(codec, new StreamScanCursor());
        this.channel = channel;
    }

    @Override
    protected void setOutput(ByteBuffer bytes) {

        if (!hasKey) {
            key = codec.decodeKey(bytes);
            hasKey = true;
            return;
        }

        V value = (bytes == null) ? null : codec.decodeValue(bytes);

        channel.onKeyValue(key, value);
        output.setCount(output.getCount() + 1);
        key = null;
        hasKey = false;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy