♻️ cache: keep redis readers by pointer

A pooled SimpleRedis holds a sync.Mutex, so appending one into rc.readers
by value copies the lock and trips go vet's copylocks check. Keep the
readers by pointer instead; the round-robin over replicas is unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
mhx
2026-09-04 11:02:13 +02:00
co-authored by Claude Opus 5
parent 23ce76d3da
commit 3ceb9617f2
2 changed files with 8 additions and 5 deletions
+5 -2
View File
@@ -130,7 +130,7 @@ func indexOfReader(rc *redisCache, r *simpleredis.SimpleRedis) int {
return -1
}
for i := range rc.readers {
if r == &rc.readers[i] {
if r == rc.readers[i] {
return i
}
}
@@ -151,7 +151,10 @@ func Test_nextReader(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
rc := &redisCache{log: logger.New("INFO", "")}
rc.readers = make([]simpleredis.SimpleRedis, tt.readers)
rc.readers = make([]*simpleredis.SimpleRedis, tt.readers)
for i := range rc.readers {
rc.readers[i] = &simpleredis.SimpleRedis{}
}
for call, want := range tt.want {
if got := indexOfReader(rc, rc.nextReader()); got != want {
t.Errorf("call %d: nextReader() -> reader[%d], want reader[%d]", call, got, want)