diff --git a/src/y-socket-io/y-socket-io.js b/src/y-socket-io/y-socket-io.js index 7337815..3f5cd9d 100644 --- a/src/y-socket-io/y-socket-io.js +++ b/src/y-socket-io/y-socket-io.js @@ -859,10 +859,13 @@ export class YSocketIO { assert(this.client) const redis = this.client.redis const key = this.getLeaderKeyOf(namespace) - const ok = await redis.set(key, this.serverId, { + const prevVal = await redis.set(key, this.serverId, { NX: true, - PX: PERSIST_LEADER_HEARTBEAT_INTERVAL + PX: PERSIST_LEADER_HEARTBEAT_INTERVAL, + GET: true }) + + const ok = prevVal === this.serverId || prevVal === null if (!ok) return false this.persistentLeaderOf.add(namespace)