optimize redis cluster readonly mode #187
Open
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.
Description
optimize cluster readonly mode by avoid MovedError in write-bound command.
How to reproduce
redis environment:
aredis connection pool settings:
fuction optimzed:
debugging application with vscode, when app invoke write command, fuction
get_node_by_slot
will return random nodes in that slot when readonly is true. this will cause MovedError exception(in write command like set, expire, setnx etc..) and cause cluster reinitialize, consume cpu usage.中文说明
aredis 集群模式在readonly设置为true的情况下,未对命令做读写区分,导致了在redis从节点上执行了写操作,触发MovedError异常,最后耗费大量cpu时间在reinitialize流程上, 在多主多从(5主5从及以上)的配置下,非常消耗cpu资源。
对readonly逻辑进行优化,读相关指令,可直接从slot对应主从中选择执行, 写相关指令,则直接返回主节点。