Skip to content

Commit cdc04ed

Browse files
committed
fix: use GET option to avoid additional call
1 parent 0d2b259 commit cdc04ed

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/y-socket-io/y-socket-io.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -859,13 +859,13 @@ export class YSocketIO {
859859
assert(this.client)
860860
const redis = this.client.redis
861861
const key = this.getLeaderKeyOf(namespace)
862-
await redis.set(key, this.serverId, {
862+
const prevVal = await redis.set(key, this.serverId, {
863863
NX: true,
864-
PX: PERSIST_LEADER_HEARTBEAT_INTERVAL
864+
PX: PERSIST_LEADER_HEARTBEAT_INTERVAL,
865+
GET: true
865866
})
866867

867-
const curLeader = await redis.get(key)
868-
const ok = curLeader === this.serverId
868+
const ok = prevVal === this.serverId || prevVal === null
869869
if (!ok) return false
870870

871871
this.persistentLeaderOf.add(namespace)

0 commit comments

Comments
 (0)