redis / ioredis

🚀 A robust, performance-focused, and full-featured Redis client for Node.js.
MIT License
14.38k stars 1.2k forks source link

Question: Is it safe to rely on `cluster.masterNodes`? #78

Closed mike-marcacci closed 9 years ago

mike-marcacci commented 9 years ago

Hey there! I got a question recently about natively supporting ioredis clusters in my redlock library, and I've got a quick question: is it safe to rely on cluster.masterNodes?

The redlock algorithm needs to be explicitly aware of all masters to ensure that a quorum is reached, and right now the library leaves the responsibility of cluster changes (failover to slaves, etc) to the user. Since it looks like ioredis already handles that quite well, I'd much rather integrate with ioredis.

My one concern is that if it's ever possible for the number of master nodes to change, this could invalidate existing locks, and I'm not exactly sure how that might be handled safely. So I just wanted to double check: is this list subject to size change or just member change?

Thanks!

luin commented 9 years ago

Nice library! Yes, the length of cluster.masterNodes is possible to change when adding or removing(e.g. failover) master nodes in the cluster, which is likely to happen in real world scenarios.

mike-marcacci commented 9 years ago

Thanks! That's what I was afraid of (but really expecting). Sounds like this will be a fun weekend challenge figuring out how to keep guarantees in the midst of cluster growth. I'll bother you on gitter if I have any specific questions :)

I'm really impressed with ioredis btw. I'll probably start moving to it for most of my projects.