Skip to content

Commit d548e3d

Browse files
committed
addressed more comments, fixed lint
1 parent f6bb761 commit d548e3d

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
@@ -6967,6 +6967,12 @@ func (cmd *VectorScoreSliceCmd) readReply(rd *proto.Reader) error {
69676967

69686968
return nil
69696969
}
6970+
func (cmd *MonitorCmd) Clone() Cmder {
6971+
// MonitorCmd cannot be safely cloned due to channels and goroutines
6972+
// Return a new MonitorCmd with the same channel
6973+
return newMonitorCmd(cmd.ctx, cmd.ch)
6974+
}
6975+
69706976
// ExtractCommandValue extracts the value from a command result using the fast enum-based approach
69716977
func ExtractCommandValue(cmd interface{}) interface{} {
69726978
// First try to get the command type using the interface
@@ -7063,9 +7069,3 @@ func ExtractCommandValue(cmd interface{}) interface{} {
70637069
// If we can't get the command type, return nil
70647070
return nil
70657071
}
7066-
7067-
func (cmd *MonitorCmd) Clone() Cmder {
7068-
// MonitorCmd cannot be safely cloned due to channels and goroutines
7069-
// Return a new MonitorCmd with the same channel
7070-
return newMonitorCmd(cmd.ctx, cmd.ch)
7071-
}

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
@@ -2079,7 +2079,7 @@ func (c *ClusterClient) cmdsInfo(ctx context.Context) (map[string]*CommandInfo,
20792079
func (c *ClusterClient) cmdInfo(ctx context.Context, name string) *CommandInfo {
20802080
// Use a separate context that won't be canceled to ensure command info lookup
20812081
// doesn't fail due to original context cancellation
2082-
cmdInfoCtx := context.Background()
2082+
cmdInfoCtx := c.context(ctx)
20832083
if c.opt.ContextTimeoutEnabled && ctx != nil {
20842084
// If context timeout is enabled, still use a reasonable timeout
20852085
var cancel context.CancelFunc
@@ -2089,13 +2089,13 @@ func (c *ClusterClient) cmdInfo(ctx context.Context, name string) *CommandInfo {
20892089

20902090
cmdsInfo, err := c.cmdsInfoCache.Get(cmdInfoCtx)
20912091
if err != nil {
2092-
internal.Logger.Printf(context.TODO(), "getting command info: %s", err)
2092+
internal.Logger.Printf(cmdInfoCtx, "getting command info: %s", err)
20932093
return nil
20942094
}
20952095

20962096
info := cmdsInfo[name]
20972097
if info == nil {
2098-
internal.Logger.Printf(context.TODO(), "info for cmd=%s not found", name)
2098+
internal.Logger.Printf(cmdInfoCtx, "info for cmd=%s not found", name)
20992099
}
21002100
return info
21012101
}

0 commit comments

Comments
 (0)