4

准备基于 redis 写个简单的集群 leader 选举,大家帮忙看看方案

 1 year ago
source link: https://www.v2ex.com/t/908307
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  Docker

准备基于 redis 写个简单的集群 leader 选举,大家帮忙看看方案

  wencan · 2 小时 16 分钟前 · 471 次点击

我对分布式和 redis 了解有限,所以还清大家帮忙看看。

服务启动时,每个实例尝试对 key 加锁,加锁成功的成为 leader 。加锁办法为 lua 脚本。有更好的加锁办法,请推荐。 leader 实例退出时,解锁,pub 消息通知其它实例,其它实例开始尝试加锁。 锁有超时时间,每次超时时间过半,leader 给 key 续时。如果 leader 非正常原因挂掉,key 会超时。 其它实例间隔随机时间尝试加锁, 或者收到 leader 退出消息时也尝试加锁,加锁成功的成为 leader 。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK