@@ -3479,7 +3479,7 @@ type CommandInfo struct {
3479
3479
LastKeyPos int8
3480
3480
StepCount int8
3481
3481
ReadOnly bool
3482
- Tips map [ string ] string
3482
+ Tips * routing. CommandPolicy
3483
3483
}
3484
3484
3485
3485
type CommandsInfoCmd struct {
@@ -3612,8 +3612,7 @@ func (cmd *CommandsInfoCmd) readReply(rd *proto.Reader) error {
3612
3612
return err
3613
3613
}
3614
3614
3615
- cmdInfo .Tips = make (map [string ]string , tipsLen )
3616
-
3615
+ rawTips := make (map [string ]string , tipsLen )
3617
3616
for f := 0 ; f < tipsLen ; f ++ {
3618
3617
tip , err := rd .ReadString ()
3619
3618
if err != nil {
@@ -3622,7 +3621,7 @@ func (cmd *CommandsInfoCmd) readReply(rd *proto.Reader) error {
3622
3621
3623
3622
// Handle tips that don't have a colon (like "nondeterministic_output")
3624
3623
if ! strings .Contains (tip , ":" ) {
3625
- cmdInfo . Tips [tip ] = ""
3624
+ rawTips [tip ] = ""
3626
3625
continue
3627
3626
}
3628
3627
@@ -3631,8 +3630,9 @@ func (cmd *CommandsInfoCmd) readReply(rd *proto.Reader) error {
3631
3630
if ! ok {
3632
3631
return fmt .Errorf ("redis: unexpected tip %q in COMMAND reply" , tip )
3633
3632
}
3634
- cmdInfo . Tips [k ] = v
3633
+ rawTips [k ] = v
3635
3634
}
3635
+ cmdInfo .Tips = parseCommandPolicies (rawTips )
3636
3636
3637
3637
if err := rd .DiscardNext (); err != nil {
3638
3638
return err
@@ -3684,47 +3684,33 @@ func (c *cmdsInfoCache) Get(ctx context.Context) (map[string]*CommandInfo, error
3684
3684
}
3685
3685
3686
3686
// ------------------------------------------------------------------------------
3687
- var BuiltinPolicies = map [string ]routing.CommandPolicy {
3688
- "ft.create" : {Request : routing .ReqSpecial , Response : routing .RespAllSucceeded },
3689
- "ft.alter" : {Request : routing .ReqSpecial , Response : routing .RespAllSucceeded },
3690
- "ft.drop" : {Request : routing .ReqSpecial , Response : routing .RespAllSucceeded },
3691
-
3692
- "mset" : {Request : routing .ReqMultiShard , Response : routing .RespAllSucceeded },
3693
- "mget" : {Request : routing .ReqMultiShard , Response : routing .RespSpecial },
3694
- "del" : {Request : routing .ReqMultiShard , Response : routing .RespAggSum },
3695
- }
3696
-
3697
- func newCommandPolicies (commandInfo map [string ]* CommandInfo ) map [string ]routing.CommandPolicy {
3698
-
3699
- table := make (map [string ]routing.CommandPolicy , len (commandInfo ))
3687
+ const requestPolicy = "request_policy"
3688
+ const responsePolicy = "response_policy"
3700
3689
3701
- for name , info := range commandInfo {
3702
- req := routing .ReqDefault
3703
- resp := routing .RespAllSucceeded
3690
+ func parseCommandPolicies ( commandInfoTips map [ string ] string ) * routing. CommandPolicy {
3691
+ req := routing .ReqDefault
3692
+ resp := routing .RespAllSucceeded
3704
3693
3705
- if tips := info .Tips ; tips != nil {
3706
- if v , ok := tips ["request_policy" ]; ok {
3707
- if p , err := routing .ParseRequestPolicy (v ); err == nil {
3708
- req = p
3709
- }
3694
+ if commandInfoTips != nil {
3695
+ if v , ok := commandInfoTips [requestPolicy ]; ok {
3696
+ if p , err := routing .ParseRequestPolicy (v ); err == nil {
3697
+ req = p
3710
3698
}
3711
- if v , ok := tips [ "response_policy" ]; ok {
3712
- if p , err := routing . ParseResponsePolicy ( v ); err == nil {
3713
- resp = p
3714
- }
3699
+ }
3700
+ if v , ok := commandInfoTips [ responsePolicy ]; ok {
3701
+ if p , err := routing . ParseResponsePolicy ( v ); err == nil {
3702
+ resp = p
3715
3703
}
3716
- } else {
3717
- return BuiltinPolicies
3718
3704
}
3719
- table [name ] = routing.CommandPolicy {Request : req , Response : resp }
3720
3705
}
3721
-
3722
- if len ( table ) == 0 {
3723
- for k , v := range BuiltinPolicies {
3724
- table [ k ] = v
3706
+ tips := make ( map [ string ] string , len ( commandInfoTips ))
3707
+ for k , v := range commandInfoTips {
3708
+ if k == requestPolicy || k == responsePolicy {
3709
+ continue
3725
3710
}
3711
+ tips [k ] = v
3726
3712
}
3727
- return table
3713
+ return & routing. CommandPolicy { Request : req , Response : resp , Tips : tips }
3728
3714
}
3729
3715
3730
3716
//------------------------------------------------------------------------------
0 commit comments