fix: 使用 SCAN 命令替代 KEYS 命令,避免大数据量时阻塞 Redis#922
Open
helloworldtang wants to merge 2 commits intodromara:devfrom
Open
fix: 使用 SCAN 命令替代 KEYS 命令,避免大数据量时阻塞 Redis#922helloworldtang wants to merge 2 commits intodromara:devfrom
helloworldtang wants to merge 2 commits intodromara:devfrom
Conversation
e6181e2 to
fd98494
Compare
问题: - KEYS 命令会阻塞 Redis,在大数据量场景下导致性能问题 - 多个线上故障与此相关 解决方案: - 使用 SCAN 命令替代 KEYS,非阻塞式遍历 影响文件: - sa-token-redis-template: 使用 RedisCallback + connection.scan() - sa-token-redis-template-jdk-serializer: 同上 - sa-token-redisx: 保持原有实现(redisx 库内部已使用 SCAN) - sa-token-jfinal-plugin: 使用 Jedis.scan() - sa-token-jboot-plugin: 使用 Jedis.scan() 新增测试: - SaTokenDaoForRedisTemplateTest: 6个测试用例覆盖 searchData 方法 - 测试通过:本机 Redis 环境,无密码 参考: - https://redis.io/commands/scan/ - https://redis.io/commands/keys/
fd98494 to
be4df0c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复内容
问题描述
使用 Redis
KEYS命令在大数据量场景下会导致 Redis 阻塞,曾引发多次线上故障。解决方案
使用
SCAN命令替代KEYS,非阻塞式遍历 key。修改文件
sa-token-redis-templatekeys()→StringRedisTemplate.scan()sa-token-redis-template-jdk-serializersa-token-redisxkeys()→keysByScan()sa-token-jfinal-pluginkeys()→Jedis.scan()sa-token-jboot-pluginkeys()→Jedis.scan()对比
修复前(阻塞):
修复后(非阻塞):
影响
测试
请在 Redis 集群环境下测试
searchData方法。