Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"context"
"fmt"
"maps"
"net"
"regexp"
"strconv"
Expand Down Expand Up @@ -2003,10 +2004,7 @@ func (cmd *StringStructMapCmd) readReply(rd *proto.Reader) error {
func (cmd *StringStructMapCmd) Clone() Cmder {
var val map[string]struct{}
if cmd.val != nil {
val = make(map[string]struct{}, len(cmd.val))
for k := range cmd.val {
val[k] = struct{}{}
}
val = maps.Clone(cmd.val)
}
return &StringStructMapCmd{
baseCmd: cmd.cloneBaseCmd(),
Expand Down
3 changes: 1 addition & 2 deletions internal/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/redis/go-redis/v9/internal"
"github.com/redis/go-redis/v9/internal/proto"
"github.com/redis/go-redis/v9/internal/util"
)

var (
Expand Down Expand Up @@ -701,7 +700,7 @@ func (p *ConnPool) popIdle() (*Conn, error) {
var cn *Conn
attempts := 0

maxAttempts := util.Min(popAttempts, n)
maxAttempts := min(popAttempts, n)
for attempts < maxAttempts {
if len(p.idleConns) == 0 {
return nil, nil
Expand Down
17 changes: 0 additions & 17 deletions internal/util/math.go

This file was deleted.

11 changes: 5 additions & 6 deletions maintnotifications/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/redis/go-redis/v9/internal"
"github.com/redis/go-redis/v9/internal/maintnotifications/logs"
"github.com/redis/go-redis/v9/internal/util"
)

// Mode represents the maintenance notifications mode
Expand Down Expand Up @@ -261,10 +260,10 @@ func (c *Config) ApplyDefaultsWithPoolConfig(poolSize int, maxActiveConns int) *
// Default: max(20x workers, PoolSize), capped by maxActiveConns or 5x pool size
workerBasedSize := result.MaxWorkers * 20
poolBasedSize := poolSize
result.HandoffQueueSize = util.Max(workerBasedSize, poolBasedSize)
result.HandoffQueueSize = max(workerBasedSize, poolBasedSize)
if c.HandoffQueueSize > 0 {
// When explicitly set: enforce minimum of 200
result.HandoffQueueSize = util.Max(200, c.HandoffQueueSize)
result.HandoffQueueSize = max(200, c.HandoffQueueSize)
}

// Cap queue size: use maxActiveConns+1 if set, otherwise 5x pool size
Expand All @@ -278,7 +277,7 @@ func (c *Config) ApplyDefaultsWithPoolConfig(poolSize int, maxActiveConns int) *
} else {
queueCap = poolSize * 5
}
result.HandoffQueueSize = util.Min(result.HandoffQueueSize, queueCap)
result.HandoffQueueSize = min(result.HandoffQueueSize, queueCap)

// Ensure minimum queue size of 2 (fallback for very small pools)
if result.HandoffQueueSize < 2 {
Expand Down Expand Up @@ -353,10 +352,10 @@ func (c *Config) applyWorkerDefaults(poolSize int) {

// When not set: min(poolSize/2, max(10, poolSize/3)) - balanced scaling approach
originalMaxWorkers := c.MaxWorkers
c.MaxWorkers = util.Min(poolSize/2, util.Max(10, poolSize/3))
c.MaxWorkers = min(poolSize/2, max(10, poolSize/3))
if originalMaxWorkers != 0 {
// When explicitly set: max(poolSize/2, set_value) - ensure at least poolSize/2 workers
c.MaxWorkers = util.Max(poolSize/2, originalMaxWorkers)
c.MaxWorkers = max(poolSize/2, originalMaxWorkers)
}

// Ensure minimum of 1 worker (fallback for very small pools)
Expand Down
21 changes: 8 additions & 13 deletions maintnotifications/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"net"
"testing"
"time"

"github.com/redis/go-redis/v9/internal/util"
)

func TestConfig(t *testing.T) {
Expand Down Expand Up @@ -130,8 +128,8 @@ func TestApplyDefaults(t *testing.T) {
workerBasedSize := result.MaxWorkers * 20
poolSize := 100 // Default pool size used in ApplyDefaults
poolBasedSize := poolSize
expectedQueueSize := util.Max(workerBasedSize, poolBasedSize)
expectedQueueSize = util.Min(expectedQueueSize, poolSize*5) // Cap by 5x pool size
expectedQueueSize := max(workerBasedSize, poolBasedSize)
expectedQueueSize = min(expectedQueueSize, poolSize*5) // Cap by 5x pool size
if result.HandoffQueueSize != expectedQueueSize {
t.Errorf("Expected HandoffQueueSize to be %d (max(20*MaxWorkers=%d, poolSize=%d) capped by 5*poolSize=%d), got %d",
expectedQueueSize, workerBasedSize, poolBasedSize, poolSize*5, result.HandoffQueueSize)
Expand All @@ -155,8 +153,8 @@ func TestApplyDefaults(t *testing.T) {
workerBasedSize := result.MaxWorkers * 20
poolSize := 100 // Default pool size used in ApplyDefaults
poolBasedSize := poolSize
expectedQueueSize := util.Max(workerBasedSize, poolBasedSize)
expectedQueueSize = util.Min(expectedQueueSize, poolSize*5) // Cap by 5x pool size
expectedQueueSize := max(workerBasedSize, poolBasedSize)
expectedQueueSize = min(expectedQueueSize, poolSize*5) // Cap by 5x pool size
if result.HandoffQueueSize != expectedQueueSize {
t.Errorf("Expected HandoffQueueSize to be %d (max(20*MaxWorkers=%d, poolSize=%d) capped by 5*poolSize=%d), got %d",
expectedQueueSize, workerBasedSize, poolBasedSize, poolSize*5, result.HandoffQueueSize)
Expand Down Expand Up @@ -224,8 +222,8 @@ func TestApplyDefaults(t *testing.T) {
workerBasedSize := result.MaxWorkers * 20
poolSize := 100 // Default pool size used in ApplyDefaults
poolBasedSize := poolSize
expectedQueueSize := util.Max(workerBasedSize, poolBasedSize)
expectedQueueSize = util.Min(expectedQueueSize, poolSize*5) // Cap by 5x pool size
expectedQueueSize := max(workerBasedSize, poolBasedSize)
expectedQueueSize = min(expectedQueueSize, poolSize*5) // Cap by 5x pool size
if result.HandoffQueueSize != expectedQueueSize {
t.Errorf("Expected HandoffQueueSize to be %d (max(20*MaxWorkers=%d, poolSize=%d) capped by 5*poolSize=%d), got %d",
expectedQueueSize, workerBasedSize, poolBasedSize, poolSize*5, result.HandoffQueueSize)
Expand All @@ -235,7 +233,6 @@ func TestApplyDefaults(t *testing.T) {
t.Errorf("Expected RelaxedTimeout to be 10s (default), got %v", result.RelaxedTimeout)
}


})
}

Expand Down Expand Up @@ -325,14 +322,12 @@ func TestIntegrationWithApplyDefaults(t *testing.T) {
t.Errorf("Expected MaxWorkers to be 50, got %d", expectedConfig.MaxWorkers)
}



// Should apply defaults for missing fields (auto-calculated queue size with hybrid scaling)
workerBasedSize := expectedConfig.MaxWorkers * 20
poolSize := 100 // Default pool size used in ApplyDefaults
poolBasedSize := poolSize
expectedQueueSize := util.Max(workerBasedSize, poolBasedSize)
expectedQueueSize = util.Min(expectedQueueSize, poolSize*5) // Cap by 5x pool size
expectedQueueSize := max(workerBasedSize, poolBasedSize)
expectedQueueSize = min(expectedQueueSize, poolSize*5) // Cap by 5x pool size
if expectedConfig.HandoffQueueSize != expectedQueueSize {
t.Errorf("Expected HandoffQueueSize to be %d (max(20*MaxWorkers=%d, poolSize=%d) capped by 5*poolSize=%d), got %d",
expectedQueueSize, workerBasedSize, poolBasedSize, poolSize*5, expectedConfig.HandoffQueueSize)
Expand Down
6 changes: 3 additions & 3 deletions sentinel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"crypto/tls"
"errors"
"net"
"sort"
"slices"
"testing"
"time"

Expand Down Expand Up @@ -671,8 +671,8 @@ func compareFailoverOptions(t *testing.T, a, e *redis.FailoverOptions) {
}

func compareSlices(t *testing.T, a, b []string, name string) {
sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
sort.Slice(b, func(i, j int) bool { return b[i] < b[j] })
slices.Sort(a)
slices.Sort(b)
if len(a) != len(b) {
t.Errorf("%s got %q, want %q", name, a, b)
}
Expand Down
Loading