springboot项目创建笔记25 之《集成redis集群哈希槽》

Exception in thread “Thread-10” 2021-07-26 13:20:56.860 [] INFO [Thread-2] com.example.service.TaskHotProductService :刷新缓存完成

org.springframework.data.redis.RedisSystemException: Error in execution; nested exception is io.lettuce.core.RedisCommandExecutionException: CROSSSLOT Keys in request don’t hash to the same slot

at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:54)

at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:52)

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:268)

at org.springframework.data.redis.connection.lettuce.LettuceZSetCommands.convertLettuceAccessException(LettuceZSetCommands.java:903)

at org.springframework.data.redis.connection.lettuce.LettuceZSetCommands.zUnionStore(LettuceZSetCommands.java:624)

at org.springframework.data.redis.connection.DefaultedRedisConnection.zUnionStore(DefaultedRedisConnection.java:868)

at org.springframework.data.redis.core.DefaultZSetOperations.lambda$unionAndStore$26(DefaultZSetOperations.java:424)

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.AbstractOperations.execute(AbstractOperations.java:95)

at org.springframework.data.redis.core.DefaultZSetOperations.unionAndStore(DefaultZSetOperations.java:424)

at com.example.service.TaskWeiBoDayHourService.refreshDay(TaskWeiBoDayHourService.java:95)

at com.example.service.TaskWeiBoDayHourService.refreshData(TaskWeiBoDayHourService.java:71)

at com.example.service.TaskWeiBoDayHourService.lambda$1(TaskWeiBoDayHourService.java:36)

at java.lang.Thread.run(Thread.java:748)

原因是在执行:

//把当前的时间key,并且把后推23个小时,共计近24个小时,求出并集存入Constants.DAY_KEY中

redisTemplate.opsForZSet().unionAndStore(Constants.HOUR_KEY + hour , otherKeys, Constants.DAY_KEY);

合并各个集合的key时,涉及多key操作,而要执行多key操作,在redis集群里被限制在同一个哈希槽中才能执行

3、解决办法

用HashTag标记,HashTag即是用{}包裹key的一个子串,只有在{}的内容才计算哈希值,这样可以保证落在同一个哈希槽中

public static final String HOUR_KEY = “{rank}:hour:”;

public static final String DAY_KEY = “{rank}:day”;

public static final String WEEK_KEY = “{rank}:week”;

public static final String MONTH_KEY = “{rank}:month”;

线程、数据库、算法、JVM、分布式、微服务、框架、Spring相关知识

一线互联网P7面试集锦+各种大厂面试集锦

学习笔记以及面试真题解析

加入社区:https://bbs.csdn.net/forums/4304bb5a486d4c3ab8389e65ecb71ac0
img-K0ersNzr-1725738253825)]

加入社区:https://bbs.csdn.net/forums/4304bb5a486d4c3ab8389e65ecb71ac0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值