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

com.lambdaworks.redis.sentinel.SentinelCommandBuilder 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!
/*
 * Copyright 2011-2016 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.lambdaworks.redis.sentinel;

import static com.lambdaworks.redis.protocol.CommandKeyword.FAILOVER;
import static com.lambdaworks.redis.protocol.CommandKeyword.RESET;
import static com.lambdaworks.redis.protocol.CommandKeyword.SLAVES;
import static com.lambdaworks.redis.protocol.CommandType.MONITOR;
import static com.lambdaworks.redis.protocol.CommandType.PING;
import static com.lambdaworks.redis.protocol.CommandType.SENTINEL;
import static com.lambdaworks.redis.protocol.CommandType.SET;

import java.util.List;
import java.util.Map;

import com.lambdaworks.redis.codec.RedisCodec;
import com.lambdaworks.redis.output.IntegerOutput;
import com.lambdaworks.redis.output.ListOfMapsOutput;
import com.lambdaworks.redis.output.MapOutput;
import com.lambdaworks.redis.output.StatusOutput;
import com.lambdaworks.redis.output.ValueListOutput;
import com.lambdaworks.redis.protocol.BaseRedisCommandBuilder;
import com.lambdaworks.redis.protocol.Command;
import com.lambdaworks.redis.protocol.CommandArgs;
import com.lambdaworks.redis.protocol.CommandKeyword;

/**
 * @author Mark Paluch
 * @since 3.0
 */
class SentinelCommandBuilder extends BaseRedisCommandBuilder {

    public SentinelCommandBuilder(RedisCodec codec) {
        super(codec);
    }

    public Command> getMasterAddrByKey(K key) {
        CommandArgs args = new CommandArgs(codec).add("get-master-addr-by-name").addKey(key);
        return createCommand(SENTINEL, new ValueListOutput(codec), args);
    }

    public Command>> masters() {
        CommandArgs args = new CommandArgs(codec).add("masters");
        return createCommand(SENTINEL, new ListOfMapsOutput(codec), args);
    }

    public Command> master(K key) {
        CommandArgs args = new CommandArgs(codec).add("master").addKey(key);
        return createCommand(SENTINEL, new MapOutput(codec), args);
    }

    public Command>> slaves(K key) {
        CommandArgs args = new CommandArgs(codec).add(SLAVES).addKey(key);
        return createCommand(SENTINEL, new ListOfMapsOutput(codec), args);
    }

    public Command reset(K key) {
        CommandArgs args = new CommandArgs(codec).add(RESET).addKey(key);
        return createCommand(SENTINEL, new IntegerOutput(codec), args);
    }

    public Command failover(K key) {
        CommandArgs args = new CommandArgs(codec).add(FAILOVER).addKey(key);
        return createCommand(SENTINEL, new StatusOutput(codec), args);
    }

    public Command monitor(K key, String ip, int port, int quorum) {
        CommandArgs args = new CommandArgs(codec).add(MONITOR).addKey(key).add(ip).add(port).add(quorum);
        return createCommand(SENTINEL, new StatusOutput(codec), args);
    }

    public Command set(K key, String option, V value) {
        CommandArgs args = new CommandArgs(codec).add(SET).addKey(key).add(option).addValue(value);
        return createCommand(SENTINEL, new StatusOutput(codec), args);
    }

    public Command ping() {
        return createCommand(PING, new StatusOutput(codec));
    }

    public Command remove(K key) {
        CommandArgs args = new CommandArgs(codec).add(CommandKeyword.REMOVE).addKey(key);
        return createCommand(SENTINEL, new StatusOutput(codec), args);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy