• Spring Boot集成Redis集群报错UnsupportedOperationException


    项目场景:

    Spring Boot集成Redis集群

    单节点配置:

    1. spring.redis.database = 0
    2. spring.redis.host = 127.0.0.1
    3. spring.redis.password = test@redis
    4. spring.redis.port = 8003
    5. # 连接超时时间 单位 ms(毫秒)
    6. spring.redis.timeout = 3000

    集群配置:

    1. #集群配置
    2. spring.redis.cluster.nodes = 127.0.0.1:8001,127.0.0.1:8002
    3. spring.redis.database = 0
    4. spring.redis.password = test@redis
    5. # 连接超时时间 单位 ms(毫秒)
    6. spring.redis.timeout = 3000

     maven依赖

    1. <dependency>
    2. <groupId>org.springframework.bootgroupId>
    3. <artifactId>spring-boot-starter-data-redisartifactId>
    4. dependency>

    问题描述

    Redis exception; nested exception is io.lettuce.core.RedisException: java.lang.UnsupportedOperationException

    完整错误 :

    1. org.springframework.data.redis.RedisSystemException: Redis exception; nested exception is io.lettuce.core.RedisException: java.lang.UnsupportedOperationException
    2.     at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:74)
    3.     at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:41)
    4.     at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:44)
    5.     at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:42)
    6.     at org.springframework.data.redis.connection.lettuce.LettuceConnection.convertLettuceAccessException(LettuceConnection.java:257)
    7.     at org.springframework.data.redis.connection.lettuce.LettuceKeyCommands.convertLettuceAccessException(LettuceKeyCommands.java:650)
    8.     at org.springframework.data.redis.connection.lettuce.LettuceKeyCommands.del(LettuceKeyCommands.java:98)
    9.     at org.springframework.data.redis.connection.DefaultedRedisConnection.del(DefaultedRedisConnection.java:61)
    10.     at org.springframework.data.redis.core.RedisTemplate.lambda$delete$2(RedisTemplate.java:709)
    11.     at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:224)
    12.     at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:184)
    13.     at org.springframework.data.redis.core.RedisTemplate.delete(RedisTemplate.java:709)

    原因分析:

    线上部署的redis版本较高,而spring boot引入的版本较低,版本不一致导致的问题


    解决方案:

    lettuce排除低版本,引入高版本

    1. <dependency>
    2. <groupId>org.springframework.bootgroupId>
    3. <artifactId>spring-boot-starter-data-redisartifactId>
    4. <exclusions>
    5. <exclusion>
    6. <artifactId>lettuce-coreartifactId>
    7. <groupId>io.lettucegroupId>
    8. exclusion>
    9. exclusions>
    10. dependency>
    11. <dependency>
    12. <artifactId>lettuce-coreartifactId>
    13. <groupId>io.lettucegroupId>
    14. <version>6.1.5.RELEASEversion>
    15. dependency>

    关联文章:Spring Boot集成redis集群拓扑动态刷新-CSDN博客

  • 相关阅读:
    分布式ID生成服务
    SpringBoot 实现启动项目后立即执行方法的几种方式
    IT人必看 | 2022年春招市场行情报告——高薪职业榜首是这些!
    LeetCode 0107.二叉树的层序遍历II - 另一种方法
    【uni-app】判断运行环境 & 配置
    openGauss学习笔记-104 openGauss 数据库管理-管理数据库安全-客户端接入之SSL证书管理-证书替换
    Uniswap 顶流之路:机制、决策与风险分析
    总结一些 spark 处理小trick
    【CV】SRCNN复现代码详解
    Unity --- UI --- 画布准备
  • 原文地址:https://blog.csdn.net/u011974797/article/details/133268647