Skip to content

Commit fa1f7d9

Browse files
committed
fix: keep pubsub commands dedicated to the same connection in single client
1 parent 9f8a06d commit fa1f7d9

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

mux.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func (m *mux) blockingMulti(ctx context.Context, cmd []Completed) (resp *redisre
224224
}
225225

226226
func (m *mux) pipeline(ctx context.Context, cmd Completed) (resp RedisResult) {
227-
slot := slotfn(cmd.Slot(), len(m.wire))
227+
slot := slotfn(len(m.wire), cmd.Slot(), cmd.NoReply())
228228
wire := m.pipe(slot)
229229
if resp = wire.Do(ctx, cmd); isBroken(resp.NonRedisError(), wire) {
230230
m.wire[slot].CompareAndSwap(wire, m.init)
@@ -233,7 +233,7 @@ func (m *mux) pipeline(ctx context.Context, cmd Completed) (resp RedisResult) {
233233
}
234234

235235
func (m *mux) pipelineMulti(ctx context.Context, cmd []Completed) (resp *redisresults) {
236-
slot := slotfn(cmd[0].Slot(), len(m.wire))
236+
slot := slotfn(len(m.wire), cmd[0].Slot(), cmd[0].NoReply())
237237
wire := m.pipe(slot)
238238
resp = wire.DoMulti(ctx, cmd...)
239239
for _, r := range resp.s {
@@ -312,7 +312,7 @@ func (m *mux) doMultiCache(ctx context.Context, slot uint16, multi []CacheableTT
312312
}
313313

314314
func (m *mux) Receive(ctx context.Context, subscribe Completed, fn func(message PubSubMessage)) error {
315-
slot := slotfn(subscribe.Slot(), len(m.wire))
315+
slot := slotfn(len(m.wire), subscribe.Slot(), subscribe.NoReply())
316316
wire := m.pipe(slot)
317317
err := wire.Receive(ctx, subscribe, fn)
318318
if isBroken(err, wire) {
@@ -361,8 +361,8 @@ func fastrand(n int) (r int) {
361361
return
362362
}
363363

364-
func slotfn(ks uint16, n int) uint16 {
365-
if n == 1 || ks == cmds.NoSlot {
364+
func slotfn(n int, ks uint16, noreply bool) uint16 {
365+
if n == 1 || ks == cmds.NoSlot || noreply {
366366
return 0
367367
}
368368
return uint16(fastrand(n))

0 commit comments

Comments
 (0)