Skip to content

Commit ade1bd5

Browse files
authored
session/redis: improve hash index calculation (#738)
1 parent 035ed87 commit ade1bd5

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

session/redis/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ require (
1111
github.com/alicebob/miniredis/v2 v2.35.0
1212
github.com/google/uuid v1.6.0
1313
github.com/redis/go-redis/v9 v9.11.0
14-
github.com/spaolacci/murmur3 v1.1.0
1514
github.com/stretchr/testify v1.10.0
1615
trpc.group/trpc-go/trpc-agent-go v0.2.0
1716
trpc.group/trpc-go/trpc-agent-go/storage/redis v0.0.3
@@ -22,6 +21,7 @@ require (
2221
github.com/davecgh/go-spew v1.1.1 // indirect
2322
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
2423
github.com/pmezard/go-difflib v1.0.0 // indirect
24+
github.com/spaolacci/murmur3 v1.1.0 // indirect
2525
github.com/yuin/gopher-lua v1.1.1 // indirect
2626
go.uber.org/multierr v1.10.0 // indirect
2727
go.uber.org/zap v1.27.0 // indirect

session/redis/service.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121

2222
"github.com/google/uuid"
2323
"github.com/redis/go-redis/v9"
24-
"github.com/spaolacci/murmur3"
2524
"trpc.group/trpc-go/trpc-agent-go/event"
2625
"trpc.group/trpc-go/trpc-agent-go/log"
2726
"trpc.group/trpc-go/trpc-agent-go/session"
@@ -488,9 +487,7 @@ func (s *Service) AppendTrackEvent(
488487
panic(r)
489488
}
490489
}()
491-
trackKey := getTrackKey(key, trackEvent.Track)
492-
n := len(s.trackEventChans)
493-
index := int(murmur3.Sum32([]byte(trackKey))) % n
490+
index := sess.Hash % len(s.trackEventChans)
494491
select {
495492
case s.trackEventChans[index] <- &trackEventPair{key: key, event: trackEvent}:
496493
case <-ctx.Done():

0 commit comments

Comments
 (0)