Skip to content

Commit cfb290a

Browse files
addressed more comments, fixed lint
1 parent d7f7ad3 commit cfb290a

File tree

3 files changed

+22
-26
lines changed

3 files changed

+22
-26
lines changed

command.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6832,6 +6832,12 @@ func (cmd *MonitorCmd) Stop() {
68326832
cmd.status = monitorStatusStop
68336833
}
68346834

6835+
func (cmd *MonitorCmd) Clone() Cmder {
6836+
// MonitorCmd cannot be safely cloned due to channels and goroutines
6837+
// Return a new MonitorCmd with the same channel
6838+
return newMonitorCmd(cmd.ctx, cmd.ch)
6839+
}
6840+
68356841
// ExtractCommandValue extracts the value from a command result using the fast enum-based approach
68366842
func ExtractCommandValue(cmd interface{}) interface{} {
68376843
// First try to get the command type using the interface
@@ -6928,9 +6934,3 @@ func ExtractCommandValue(cmd interface{}) interface{} {
69286934
// If we can't get the command type, return nil
69296935
return nil
69306936
}
6931-
6932-
func (cmd *MonitorCmd) Clone() Cmder {
6933-
// MonitorCmd cannot be safely cloned due to channels and goroutines
6934-
// Return a new MonitorCmd with the same channel
6935-
return newMonitorCmd(cmd.ctx, cmd.ch)
6936-
}

internal/routing/aggregator.go

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package routing
22

33
import (
4+
"errors"
45
"fmt"
56
"math"
67
"sync"
@@ -9,6 +10,13 @@ import (
910
"github.com/redis/go-redis/v9/internal/util"
1011
)
1112

13+
var (
14+
ErrMaxAggregation = errors.New("redis: no valid results to aggregate for max operation")
15+
ErrMinAggregation = errors.New("redis: no valid results to aggregate for min operation")
16+
ErrAndAggregation = errors.New("redis: no valid results to aggregate for logical AND operation")
17+
ErrOrAggregation = errors.New("redis: no valid results to aggregate for logical OR operation")
18+
)
19+
1220
// ResponseAggregator defines the interface for aggregating responses from multiple shards.
1321
type ResponseAggregator interface {
1422
// Add processes a single shard response.
@@ -171,11 +179,6 @@ func (a *AggSumAggregator) Result() (interface{}, error) {
171179
type AggMinAggregator struct {
172180
err atomic.Value
173181
res *util.AtomicMin
174-
175-
mu sync.Mutex
176-
min int64
177-
hasResult bool
178-
firstErr error
179182
}
180183

181184
func (a *AggMinAggregator) Add(result interface{}, err error) error {
@@ -207,7 +210,7 @@ func (a *AggMinAggregator) Result() (interface{}, error) {
207210

208211
val, hasVal := a.res.Min()
209212
if !hasVal {
210-
return nil, fmt.Errorf("redis: no valid results to aggregate for min operation")
213+
return nil, ErrMinAggregation
211214
}
212215
return val, nil
213216
}
@@ -247,7 +250,7 @@ func (a *AggMaxAggregator) Result() (interface{}, error) {
247250

248251
val, hasVal := a.res.Max()
249252
if !hasVal {
250-
return nil, fmt.Errorf("redis: no valid results to aggregate for max operation")
253+
return nil, ErrMaxAggregation
251254
}
252255
return val, nil
253256
}
@@ -293,7 +296,7 @@ func (a *AggLogicalAndAggregator) Result() (interface{}, error) {
293296
}
294297

295298
if !a.hasResult.Load() {
296-
return nil, fmt.Errorf("redis: no valid results to aggregate for logical AND operation")
299+
return nil, ErrAndAggregation
297300
}
298301
return a.res.Load() != 0, nil
299302
}
@@ -339,7 +342,7 @@ func (a *AggLogicalOrAggregator) Result() (interface{}, error) {
339342
}
340343

341344
if !a.hasResult.Load() {
342-
return nil, fmt.Errorf("redis: no valid results to aggregate for logical OR operation")
345+
return nil, ErrOrAggregation
343346
}
344347
return a.res.Load() != 0, nil
345348
}
@@ -533,13 +536,6 @@ func (a *SpecialAggregator) Result() (interface{}, error) {
533536
return nil, nil
534537
}
535538

536-
// SetAggregatorFunc allows setting custom aggregation logic for special commands.
537-
func (a *SpecialAggregator) SetAggregatorFunc(fn func([]interface{}, []error) (interface{}, error)) {
538-
a.mu.Lock()
539-
defer a.mu.Unlock()
540-
a.aggregatorFunc = fn
541-
}
542-
543539
// SpecialAggregatorRegistry holds custom aggregation functions for specific commands.
544540
var SpecialAggregatorRegistry = make(map[string]func([]interface{}, []error) (interface{}, error))
545541

@@ -552,7 +548,7 @@ func RegisterSpecialAggregator(cmdName string, fn func([]interface{}, []error) (
552548
func NewSpecialAggregator(cmdName string) *SpecialAggregator {
553549
agg := &SpecialAggregator{}
554550
if fn, exists := SpecialAggregatorRegistry[cmdName]; exists {
555-
agg.SetAggregatorFunc(fn)
551+
agg.aggregatorFunc = fn
556552
}
557553
return agg
558554
}

osscluster.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,7 +1865,7 @@ func (c *ClusterClient) cmdsInfo(ctx context.Context) (map[string]*CommandInfo,
18651865
func (c *ClusterClient) cmdInfo(ctx context.Context, name string) *CommandInfo {
18661866
// Use a separate context that won't be canceled to ensure command info lookup
18671867
// doesn't fail due to original context cancellation
1868-
cmdInfoCtx := context.Background()
1868+
cmdInfoCtx := c.context(ctx)
18691869
if c.opt.ContextTimeoutEnabled && ctx != nil {
18701870
// If context timeout is enabled, still use a reasonable timeout
18711871
var cancel context.CancelFunc
@@ -1875,13 +1875,13 @@ func (c *ClusterClient) cmdInfo(ctx context.Context, name string) *CommandInfo {
18751875

18761876
cmdsInfo, err := c.cmdsInfoCache.Get(cmdInfoCtx)
18771877
if err != nil {
1878-
internal.Logger.Printf(context.TODO(), "getting command info: %s", err)
1878+
internal.Logger.Printf(cmdInfoCtx, "getting command info: %s", err)
18791879
return nil
18801880
}
18811881

18821882
info := cmdsInfo[name]
18831883
if info == nil {
1884-
internal.Logger.Printf(context.TODO(), "info for cmd=%s not found", name)
1884+
internal.Logger.Printf(cmdInfoCtx, "info for cmd=%s not found", name)
18851885
}
18861886
return info
18871887
}

0 commit comments

Comments
 (0)