Spring Boot集成Redis集群报错UnsupportedOperationException

文章讲述了在SpringBoot项目中集成Redis集群时遇到`UnsupportedOperationException`的问题,原因是线上Redis版本高于SpringBoot引入的Redis版本。解决方案是排除低版本Lettuce并引入对应高版本。
摘要由CSDN通过智能技术生成

项目场景:

Spring Boot集成Redis集群

单节点配置:

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

集群配置:

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

 maven依赖

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

问题描述

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

完整错误 :

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

原因分析:

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


解决方案:

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

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-data-redis</artifactId>
	<!-- 排除低版本,部署的redis版本较高,低版本lettuce会报错java.lang.UnsupportedOperationException -->
	<exclusions>
		<exclusion>
			<artifactId>lettuce-core</artifactId>
			<groupId>io.lettuce</groupId>
		</exclusion>
	</exclusions>
</dependency>
<!-- 引入高版本 -->
<dependency>
	<artifactId>lettuce-core</artifactId>
	<groupId>io.lettuce</groupId>
	<version>6.1.5.RELEASE</version>
</dependency>

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

涛哥是个大帅比

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值