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

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

import io.lettuce.core.internal.LettuceAssert;
import io.lettuce.core.protocol.CommandArgs;
import io.lettuce.core.protocol.CommandKeyword;
import io.lettuce.core.protocol.ProtocolKeyword;

/**
 * Argument list builder for the Redis BLMPOP and
 * LPOP commands. Static import the methods from {@link Builder} and chain the
 * method calls: {@code left().count(…)}.
 *
 * @author Mark Paluch
 * @since 6.2
 */
public class LMPopArgs implements CompositeArgument {

    private final ProtocolKeyword direction;

    private Long count;

    private LMPopArgs(ProtocolKeyword source, Long count) {
        this.direction = source;
        this.count = count;
    }

    /**
     * Builder entry points for {@link LMPopArgs}.
     */
    public static class Builder {

        /**
         * Utility constructor.
         */
        private Builder() {
        }

        /**
         * Creates new {@link LMPopArgs} setting with {@code LEFT} direction.
         *
         * @return new {@link LMPopArgs} with args set.
         */
        public static LMPopArgs left() {
            return new LMPopArgs(CommandKeyword.LEFT, null);
        }

        /**
         * Creates new {@link LMPopArgs} setting with {@code RIGHT} direction.
         *
         * @return new {@link LMPopArgs} with args set.
         */
        public static LMPopArgs right() {
            return new LMPopArgs(CommandKeyword.RIGHT, null);
        }

    }

    /**
     * Set the {@code count} of entries to return.
     *
     * @param count number greater 0.
     * @return {@code this}
     */
    public LMPopArgs count(long count) {

        LettuceAssert.isTrue(count > 0, "Count must be greater 0");

        this.count = count;
        return this;
    }

    @Override
    public  void build(CommandArgs args) {
        args.add(direction);

        if (count != null) {
            args.add(CommandKeyword.COUNT).add(count);
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy