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
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-data-redisartifactId>
- 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.bootgroupId>
- <artifactId>spring-boot-starter-data-redisartifactId>
-
- <exclusions>
- <exclusion>
- <artifactId>lettuce-coreartifactId>
- <groupId>io.lettucegroupId>
- exclusion>
- exclusions>
- dependency>
- <dependency>
- <artifactId>lettuce-coreartifactId>
- <groupId>io.lettucegroupId>
- <version>6.1.5.RELEASEversion>
- dependency>