io.lettuce.core.RedisConnectionException

io.lettuce.core.RedisConnectionException: Unable to connect to 127.0.0.1:6379

html 复制代码
/*
 * Copyright 2011-2022 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
 *
 *      https://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 io.lettuce.core;

import java.net.SocketAddress;

/**
 * Exception for connection failures.
 *
 * @author Mark Paluch
 */
@SuppressWarnings("serial")
public class RedisConnectionException extends RedisException {

    /**
     * Create a {@code RedisConnectionException} with the specified detail message.
     *
     * @param msg the detail message.
     */
    public RedisConnectionException(String msg) {
        super(msg);
    }

    /**
     * Create a {@code RedisConnectionException} with the specified detail message and nested exception.
     *
     * @param msg the detail message.
     * @param cause the nested exception.
     */
    public RedisConnectionException(String msg, Throwable cause) {
        super(msg, cause);
    }

    /**
     * Create a new {@link RedisConnectionException} given {@link SocketAddress} and the {@link Throwable cause}.
     *
     * @param remoteAddress remote socket address.
     * @param cause the nested exception.
     * @return the {@link RedisConnectionException}.
     * @since 4.4
     */
    public static RedisConnectionException create(SocketAddress remoteAddress, Throwable cause) {
        return create(remoteAddress == null ? null : remoteAddress.toString(), cause);
    }

    /**
     * Create a new {@link RedisConnectionException} given {@code remoteAddress} and the {@link Throwable cause}.
     *
     * @param remoteAddress remote address.
     * @param cause the nested exception.
     * @return the {@link RedisConnectionException}.
     * @since 5.1
     */
    public static RedisConnectionException create(String remoteAddress, Throwable cause) {

        if (remoteAddress == null) {

            if (cause instanceof RedisConnectionException) {
                return new RedisConnectionException(cause.getMessage(), cause.getCause());
            }

            return new RedisConnectionException(null, cause);
        }

        return new RedisConnectionException(String.format("Unable to connect to %s", remoteAddress), cause);
    }

    /**
     * Create a new {@link RedisConnectionException} given {@link Throwable cause}.
     *
     * @param cause the exception.
     * @return the {@link RedisConnectionException}.
     * @since 5.1
     */
    public static RedisConnectionException create(Throwable cause) {

        if (cause instanceof RedisConnectionException) {
            return new RedisConnectionException(cause.getMessage(), cause.getCause());
        }

        return new RedisConnectionException("Unable to connect", cause);
    }

    /**
     * @param error the error message.
     * @return {@code true} if the {@code error} message indicates Redis protected mode.
     * @since 5.0.1
     */
    public static boolean isProtectedMode(String error) {
        return error != null && error.startsWith("DENIED");
    }

}
相关推荐
一只小闪闪8 分钟前
easy-trans java数据通用翻译框架v2.3.0
java·后端·架构
2601_9620558110 分钟前
Spring全部注解
java·后端·spring
chjif22 分钟前
一张照片和一段声音如何生成口播视频:MiniMax H3 音画同步实测
java·前端·javascript
何以解忧,唯有..32 分钟前
LangChain 中 Pydantic 格式输出:结构化输出的完整指南
java·开发语言·langchain
hweiyu001 小时前
Redis命令:MIGRATE
redis·缓存
旧梦95271 小时前
Java 捕获多个异常:从基础语法到最佳实践
java·开发语言
2601_962189601 小时前
【SpringBoot】使用IDEA创建SpringBoot项目
java·spring boot·intellij-idea
步行cgn1 小时前
Spring Boot 启动报错:MissingServletWebServerFactoryBean 的排查与解决
java·spring boot·后端
XLYcmy1 小时前
HTML/CSS/JS 基础与 Vue 技术栈深度解析
java·前端·css·html·vue3·vue2·api
~木雨1 小时前
String 底层原理与常量池全解析:byte []+coder、intern 陷阱、substring 内存泄漏,一篇讲透
java·jvm·内存优化·string·字符串常量池