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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D95Nh68xKXhynPXHzozrXp
This commit is contained in:
mhx
2026-08-25 19:40:35 +02:00
co-authored by Claude Opus 5
parent ae7481caa5
commit f359d5d935
2 changed files with 10 additions and 5 deletions
+5 -3
View File
@@ -52,7 +52,7 @@ func (localCache) delete(key string) {
type redisCache struct {
log *slog.Logger
writer simpleredis.SimpleRedis
readers []simpleredis.SimpleRedis
readers []*simpleredis.SimpleRedis
counter atomic.Uint64
}
@@ -62,7 +62,7 @@ func (rc *redisCache) nextReader() *simpleredis.SimpleRedis {
return &rc.writer
}
idx := rc.counter.Add(1) % uint64(n)
return &rc.readers[idx]
return rc.readers[idx]
}
func (rc *redisCache) get(key string) (string, error) {
@@ -115,7 +115,9 @@ func (c *Client) New(log *slog.Logger, isRedis bool, writeHost string, readHosts
rc := &redisCache{log: log}
rc.writer.Init(writeHost, pass, database)
for _, h := range readHosts {
var r simpleredis.SimpleRedis
// A pooled SimpleRedis holds a mutex, so it is kept by pointer:
// appending it by value would copy the lock along with it.
r := &simpleredis.SimpleRedis{}
r.Init(h, pass, database)
rc.readers = append(rc.readers, r)
}