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

org.redisson.client.protocol.RedisCommand Maven / Gradle / Ivy

There is a newer version: 3.34.1
Show newest version
/**
 * Copyright (c) 2013-2022 Nikita Koksharov
 *
 * 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 org.redisson.client.protocol;

import org.redisson.client.protocol.convertor.Convertor;
import org.redisson.client.protocol.convertor.EmptyConvertor;
import org.redisson.client.protocol.decoder.MultiDecoder;

/**
 * 
 * @author Nikita Koksharov
 *
 * @param  return type
 */
public class RedisCommand {

    private final String name;
    private final String subName;

    private final MultiDecoder replayMultiDecoder;
    Convertor convertor = new EmptyConvertor();

    /**
     * Copy command and change name
     *
     * @param command - source command
     * @param name - new command name
     */
    public RedisCommand(RedisCommand command, String name) {
        this.name = name;
        this.subName = command.subName;
        this.replayMultiDecoder = command.replayMultiDecoder;
        this.convertor = command.convertor;
    }
    
    public RedisCommand(RedisCommand command, String name, Convertor convertor) {
        this.name = name;
        this.subName = command.subName;
        this.replayMultiDecoder = command.replayMultiDecoder;
        this.convertor = convertor;
    }

    public RedisCommand(String name) {
        this(name, (String) null);
    }

    public RedisCommand(String name, String subName) {
        this(name, subName, (MultiDecoder) null);
    }

    public RedisCommand(String name, String subName, Convertor convertor) {
        this(name, subName);
        this.convertor = convertor;
    }

    public RedisCommand(String name, Convertor convertor) {
        this(name, null, (MultiDecoder) null);
        this.convertor = convertor;
    }

    public RedisCommand(String name, MultiDecoder replayMultiDecoder) {
        this(name, null, replayMultiDecoder);
    }

    public RedisCommand(String name, MultiDecoder replayMultiDecoder, Convertor convertor) {
        this(name, replayMultiDecoder);
        this.convertor = convertor;
    }

    public RedisCommand(String name, String subName, MultiDecoder replayMultiDecoder) {
        super();
        this.name = name;
        this.subName = subName;
        if (replayMultiDecoder != null) {
            this.replayMultiDecoder = replayMultiDecoder;
        } else {
            this.replayMultiDecoder = (parts, state) -> (R) parts;
        }
    }

    public String getSubName() {
        return subName;
    }

    public String getName() {
        return name;
    }

    public MultiDecoder getReplayMultiDecoder() {
        return replayMultiDecoder;
    }

    public Convertor getConvertor() {
        return convertor;
    }

    public boolean isNoRetry() {
        return RedisCommands.NO_RETRY.contains(getName())
                || RedisCommands.NO_RETRY_COMMANDS.contains(this);
    }

    public boolean isBlockingCommand() {
        return RedisCommands.BLOCKING_COMMAND_NAMES.contains(getName())
                || RedisCommands.BLOCKING_COMMANDS.contains(this);
    }

    public String toString() {
        StringBuilder str = new StringBuilder();
        str.append("(").append(name);
        if (subName != null) {
            str.append(" ").append(subName);
        }
        str.append(")");
        return str.toString();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy