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

io.lettuce.core.output.VoidOutput 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.codec.RedisCodec;

/**
 * {@link Void} command output to consume data silently without actually processing it. Creating {@link VoidCodec} through its
 * constructor will preserve its error decoding since decoding errors is stateful. Obtaining {@link VoidOutput} through
 * {@link #create()} will return an instance that does not decode errors.
 *
 * @param  Key type.
 * @param  Value type.
 * @author Mark Paluch
 * @since 6.0.2
 */
public class VoidOutput extends CommandOutput {

    private static final VoidOutput INSTANCE = new VoidOutput(VoidCodec.INSTANCE) {

        @Override
        public void setError(String error) {
            // no-op
        }

        @Override
        public void setError(ByteBuffer error) {
            // no-op
        }

    };

    /**
     * Initialize a new instance that decodes errors.
     */
    @SuppressWarnings("unchecked")
    public VoidOutput() {
        this((RedisCodec) VoidCodec.INSTANCE);
    }

    /**
     * Initialize a new instance that decodes errors.
     *
     * @param codec used for type inference, must not be {@code null}.
     */
    public VoidOutput(RedisCodec codec) {
        super(codec, null);
    }

    /**
     * Returns an instance of {@link VoidOutput} coerced to the expected generics. Since this codec does not decode any data at
     * all, it's safe to use this way. Note that this method is only suitable for fire-and-forget usage since errors are not
     * decoded.
     *
     * @param  Key type.
     * @param  Value type.
     * @return the {@link VoidOutput} instance.
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static  VoidOutput create() {
        return (VoidOutput) INSTANCE;
    }

    @Override
    public void set(ByteBuffer bytes) {
        // no-op
    }

    @Override
    public void set(long integer) {
        // no-op
    }

    @Override
    public void setSingle(ByteBuffer bytes) {
        // no-op
    }

    @Override
    public void setBigNumber(ByteBuffer bytes) {
        // no-op
    }

    @Override
    public void set(double number) {
        // no-op
    }

    @Override
    public void set(boolean value) {
        // no-op
    }

    enum VoidCodec implements RedisCodec {

        INSTANCE;

        @Override
        public Void decodeKey(ByteBuffer bytes) {
            return null;
        }

        @Override
        public Void decodeValue(ByteBuffer bytes) {
            return null;
        }

        @Override
        public ByteBuffer encodeKey(Void key) {
            return null;
        }

        @Override
        public ByteBuffer encodeValue(Void value) {
            return null;
        }

    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy