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

io.lettuce.core.protocol.PristineFallbackCommand 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.protocol;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;

import io.lettuce.core.codec.StringCodec;
import io.lettuce.core.output.CommandOutput;
import io.netty.buffer.ByteBuf;

/**
 * Generic fallback command to collect arbitrary Redis responses in a {@link List} represented as String. Used as buffer when
 * received a Redis response without a command to correlate.
 *
 * @author Mark Paluch
 * @since 4.5
 */
class PristineFallbackCommand implements RedisCommand> {

    private final CommandOutput> output;

    private volatile boolean complete;

    PristineFallbackCommand() {
        this.output = new FallbackOutput();
    }

    @Override
    public CommandOutput> getOutput() {
        return output;
    }

    @Override
    public void complete() {
        complete = true;
    }

    @Override
    public void cancel() {
        complete = true;
    }

    @Override
    public CommandArgs getArgs() {
        return null;
    }

    @Override
    public boolean completeExceptionally(Throwable throwable) {
        return false;
    }

    @Override
    public ProtocolKeyword getType() {
        return null;
    }

    @Override
    public void encode(ByteBuf buf) {
    }

    @Override
    public boolean isCancelled() {
        return false;
    }

    @Override
    public boolean isDone() {
        return complete;
    }

    @Override
    public void setOutput(CommandOutput> output) {
    }

    static class FallbackOutput extends CommandOutput> {

        FallbackOutput() {
            super(StringCodec.ASCII, new ArrayList<>());
        }

        @Override
        public void set(ByteBuffer bytes) {
            output.add(bytes != null ? codec.decodeKey(bytes) : null);
        }

        @Override
        public void set(long integer) {
            output.add("" + integer);
        }

    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy