Skip to content

Commit d9a6a19

Browse files
committed
Merge branch 'master' into load-balance-search-commands-to-shards
2 parents 68d8dc6 + c176672 commit d9a6a19

File tree

7 files changed

+542
-3
lines changed

7 files changed

+542
-3
lines changed

command.go

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4508,7 +4508,6 @@ func parseCommandPolicies(commandInfoTips map[string]string) *routing.CommandPol
45084508
req := routing.ReqDefault
45094509
resp := routing.RespAllSucceeded
45104510

4511-
45124511
tips := make(map[string]string, len(commandInfoTips))
45134512
for k, v := range commandInfoTips {
45144513
if k == requestPolicy {
@@ -4666,6 +4665,95 @@ func (cmd *SlowLogCmd) Clone() Cmder {
46664665

46674666
//-----------------------------------------------------------------------
46684667

4668+
type Latency struct {
4669+
Name string
4670+
Time time.Time
4671+
Latest time.Duration
4672+
Max time.Duration
4673+
}
4674+
4675+
type LatencyCmd struct {
4676+
baseCmd
4677+
val []Latency
4678+
}
4679+
4680+
var _ Cmder = (*LatencyCmd)(nil)
4681+
4682+
func NewLatencyCmd(ctx context.Context, args ...interface{}) *LatencyCmd {
4683+
return &LatencyCmd{
4684+
baseCmd: baseCmd{
4685+
ctx: ctx,
4686+
args: args,
4687+
},
4688+
}
4689+
}
4690+
4691+
func (cmd *LatencyCmd) SetVal(val []Latency) {
4692+
cmd.val = val
4693+
}
4694+
4695+
func (cmd *LatencyCmd) Val() []Latency {
4696+
return cmd.val
4697+
}
4698+
4699+
func (cmd *LatencyCmd) Result() ([]Latency, error) {
4700+
return cmd.val, cmd.err
4701+
}
4702+
4703+
func (cmd *LatencyCmd) String() string {
4704+
return cmdString(cmd, cmd.val)
4705+
}
4706+
4707+
func (cmd *LatencyCmd) readReply(rd *proto.Reader) error {
4708+
n, err := rd.ReadArrayLen()
4709+
if err != nil {
4710+
return err
4711+
}
4712+
cmd.val = make([]Latency, n)
4713+
for i := 0; i < len(cmd.val); i++ {
4714+
nn, err := rd.ReadArrayLen()
4715+
if err != nil {
4716+
return err
4717+
}
4718+
if nn < 3 {
4719+
return fmt.Errorf("redis: got %d elements in latency get, expected at least 3", nn)
4720+
}
4721+
if cmd.val[i].Name, err = rd.ReadString(); err != nil {
4722+
return err
4723+
}
4724+
createdAt, err := rd.ReadInt()
4725+
if err != nil {
4726+
return err
4727+
}
4728+
cmd.val[i].Time = time.Unix(createdAt, 0)
4729+
latest, err := rd.ReadInt()
4730+
if err != nil {
4731+
return err
4732+
}
4733+
cmd.val[i].Latest = time.Duration(latest) * time.Millisecond
4734+
maximum, err := rd.ReadInt()
4735+
if err != nil {
4736+
return err
4737+
}
4738+
cmd.val[i].Max = time.Duration(maximum) * time.Millisecond
4739+
}
4740+
return nil
4741+
}
4742+
4743+
func (cmd *LatencyCmd) Clone() Cmder {
4744+
var val []Latency
4745+
if cmd.val != nil {
4746+
val = make([]Latency, len(cmd.val))
4747+
copy(val, cmd.val)
4748+
}
4749+
return &LatencyCmd{
4750+
baseCmd: cmd.cloneBaseCmd(),
4751+
val: val,
4752+
}
4753+
}
4754+
4755+
//-----------------------------------------------------------------------
4756+
46694757
type MapStringInterfaceCmd struct {
46704758
baseCmd
46714759

commands.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,13 @@ type Cmdable interface {
211211
ShutdownNoSave(ctx context.Context) *StatusCmd
212212
SlaveOf(ctx context.Context, host, port string) *StatusCmd
213213
SlowLogGet(ctx context.Context, num int64) *SlowLogCmd
214+
SlowLogLen(ctx context.Context) *IntCmd
215+
SlowLogReset(ctx context.Context) *StatusCmd
214216
Time(ctx context.Context) *TimeCmd
215217
DebugObject(ctx context.Context, key string) *StringCmd
216218
MemoryUsage(ctx context.Context, key string, samples ...int) *IntCmd
219+
Latency(ctx context.Context) *LatencyCmd
220+
LatencyReset(ctx context.Context, events ...interface{}) *StatusCmd
217221

218222
ModuleLoadex(ctx context.Context, conf *ModuleLoadexConfig) *StringCmd
219223

@@ -673,6 +677,34 @@ func (c cmdable) SlowLogGet(ctx context.Context, num int64) *SlowLogCmd {
673677
return cmd
674678
}
675679

680+
func (c cmdable) SlowLogLen(ctx context.Context) *IntCmd {
681+
cmd := NewIntCmd(ctx, "slowlog", "len")
682+
_ = c(ctx, cmd)
683+
return cmd
684+
}
685+
686+
func (c cmdable) SlowLogReset(ctx context.Context) *StatusCmd {
687+
cmd := NewStatusCmd(ctx, "slowlog", "reset")
688+
_ = c(ctx, cmd)
689+
return cmd
690+
}
691+
692+
func (c cmdable) Latency(ctx context.Context) *LatencyCmd {
693+
cmd := NewLatencyCmd(ctx, "latency", "latest")
694+
_ = c(ctx, cmd)
695+
return cmd
696+
}
697+
698+
func (c cmdable) LatencyReset(ctx context.Context, events ...interface{}) *StatusCmd {
699+
args := make([]interface{}, 2+len(events))
700+
args[0] = "latency"
701+
args[1] = "reset"
702+
copy(args[2:], events)
703+
cmd := NewStatusCmd(ctx, args...)
704+
_ = c(ctx, cmd)
705+
return cmd
706+
}
707+
676708
func (c cmdable) Sync(_ context.Context) {
677709
panic("not implemented")
678710
}

0 commit comments

Comments
 (0)