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

}
相关推荐
IDRSolutions_CN9 分钟前
PDF 转 HTML5 —— HTML5 填充图形不支持 Even-Odd 奇偶规则?(第二部分)
java·经验分享·pdf·软件工程·团队开发
hello早上好12 分钟前
Spring不同类型的ApplicationContext的创建方式
java·后端·架构
HelloWord~1 小时前
SpringSecurity+vue通用权限系统2
java·vue.js
让我上个超影吧1 小时前
黑马点评【基于redis实现共享session登录】
java·redis
BillKu2 小时前
Java + Spring Boot + Mybatis 插入数据后,获取自增 id 的方法
java·tomcat·mybatis
全栈凯哥2 小时前
Java详解LeetCode 热题 100(26):LeetCode 142. 环形链表 II(Linked List Cycle II)详解
java·算法·leetcode·链表
chxii2 小时前
12.7Swing控件6 JList
java
全栈凯哥2 小时前
Java详解LeetCode 热题 100(27):LeetCode 21. 合并两个有序链表(Merge Two Sorted Lists)详解
java·算法·leetcode·链表
YuTaoShao2 小时前
Java八股文——集合「List篇」
java·开发语言·list
PypYCCcccCc2 小时前
支付系统架构图
java·网络·金融·系统架构