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");
    }

}
相关推荐
大梦谁先觉i4 分钟前
Spring 实现 3 种异步流式接口,干掉接口超时烦恼
java·后端·spring
Lenyiin4 分钟前
第 97 场周赛:公平的糖果交换、查找和替换模式、根据前序和后序遍历构造二叉树、子序列宽度之和
java·c++·python·leetcode·周赛·lenyiin
明天更新14 分钟前
oss存储分片的简单思路
java
凌冰_21 分钟前
IDEA2025 搭建Web并部署到Tomcat运行Servlet+Thymeleaf
java·servlet·tomcat
Seven9722 分钟前
剑指offer-53、表达数值的字符串
java
木楚23 分钟前
在idea中构建传统ssm框架的步骤和方式
java·ide·intellij-idea
不穿格子的程序员25 分钟前
Redis篇9——Redis深度剖析:
数据库·redis·多线程·事务回滚·ap·cp
董世昌4125 分钟前
JavaScript 中 undefined 和 not defined 的区别
java·服务器·javascript
今晚务必早点睡28 分钟前
Redis——快速入门第五课:Redis 常见坑 & 面试高频问题
数据库·redis·面试
理人综艺好会29 分钟前
Redis学习之单线程
redis·websocket·学习