@@ -3414,7 +3414,7 @@ type CommandInfo struct {
3414
3414
LastKeyPos int8
3415
3415
StepCount int8
3416
3416
ReadOnly bool
3417
- Tips map [ string ] string
3417
+ Tips * routing. CommandPolicy
3418
3418
}
3419
3419
3420
3420
type CommandsInfoCmd struct {
@@ -3547,8 +3547,7 @@ func (cmd *CommandsInfoCmd) readReply(rd *proto.Reader) error {
3547
3547
return err
3548
3548
}
3549
3549
3550
- cmdInfo .Tips = make (map [string ]string , tipsLen )
3551
-
3550
+ rawTips := make (map [string ]string , tipsLen )
3552
3551
for f := 0 ; f < tipsLen ; f ++ {
3553
3552
tip , err := rd .ReadString ()
3554
3553
if err != nil {
@@ -3557,7 +3556,7 @@ func (cmd *CommandsInfoCmd) readReply(rd *proto.Reader) error {
3557
3556
3558
3557
// Handle tips that don't have a colon (like "nondeterministic_output")
3559
3558
if ! strings .Contains (tip , ":" ) {
3560
- cmdInfo . Tips [tip ] = ""
3559
+ rawTips [tip ] = ""
3561
3560
continue
3562
3561
}
3563
3562
@@ -3566,8 +3565,9 @@ func (cmd *CommandsInfoCmd) readReply(rd *proto.Reader) error {
3566
3565
if ! ok {
3567
3566
return fmt .Errorf ("redis: unexpected tip %q in COMMAND reply" , tip )
3568
3567
}
3569
- cmdInfo . Tips [k ] = v
3568
+ rawTips [k ] = v
3570
3569
}
3570
+ cmdInfo .Tips = parseCommandPolicies (rawTips )
3571
3571
3572
3572
if err := rd .DiscardNext (); err != nil {
3573
3573
return err
@@ -3620,47 +3620,33 @@ func (c *cmdsInfoCache) Get(ctx context.Context) (map[string]*CommandInfo, error
3620
3620
}
3621
3621
3622
3622
// ------------------------------------------------------------------------------
3623
- var BuiltinPolicies = map [string ]routing.CommandPolicy {
3624
- "ft.create" : {Request : routing .ReqSpecial , Response : routing .RespAllSucceeded },
3625
- "ft.alter" : {Request : routing .ReqSpecial , Response : routing .RespAllSucceeded },
3626
- "ft.drop" : {Request : routing .ReqSpecial , Response : routing .RespAllSucceeded },
3627
-
3628
- "mset" : {Request : routing .ReqMultiShard , Response : routing .RespAllSucceeded },
3629
- "mget" : {Request : routing .ReqMultiShard , Response : routing .RespSpecial },
3630
- "del" : {Request : routing .ReqMultiShard , Response : routing .RespAggSum },
3631
- }
3632
-
3633
- func newCommandPolicies (commandInfo map [string ]* CommandInfo ) map [string ]routing.CommandPolicy {
3634
-
3635
- table := make (map [string ]routing.CommandPolicy , len (commandInfo ))
3623
+ const requestPolicy = "request_policy"
3624
+ const responsePolicy = "response_policy"
3636
3625
3637
- for name , info := range commandInfo {
3638
- req := routing .ReqDefault
3639
- resp := routing .RespAllSucceeded
3626
+ func parseCommandPolicies ( commandInfoTips map [ string ] string ) * routing. CommandPolicy {
3627
+ req := routing .ReqDefault
3628
+ resp := routing .RespAllSucceeded
3640
3629
3641
- if tips := info .Tips ; tips != nil {
3642
- if v , ok := tips ["request_policy" ]; ok {
3643
- if p , err := routing .ParseRequestPolicy (v ); err == nil {
3644
- req = p
3645
- }
3630
+ if commandInfoTips != nil {
3631
+ if v , ok := commandInfoTips [requestPolicy ]; ok {
3632
+ if p , err := routing .ParseRequestPolicy (v ); err == nil {
3633
+ req = p
3646
3634
}
3647
- if v , ok := tips [ "response_policy" ]; ok {
3648
- if p , err := routing . ParseResponsePolicy ( v ); err == nil {
3649
- resp = p
3650
- }
3635
+ }
3636
+ if v , ok := commandInfoTips [ responsePolicy ]; ok {
3637
+ if p , err := routing . ParseResponsePolicy ( v ); err == nil {
3638
+ resp = p
3651
3639
}
3652
- } else {
3653
- return BuiltinPolicies
3654
3640
}
3655
- table [name ] = routing.CommandPolicy {Request : req , Response : resp }
3656
3641
}
3657
-
3658
- if len ( table ) == 0 {
3659
- for k , v := range BuiltinPolicies {
3660
- table [ k ] = v
3642
+ tips := make ( map [ string ] string , len ( commandInfoTips ))
3643
+ for k , v := range commandInfoTips {
3644
+ if k == requestPolicy || k == responsePolicy {
3645
+ continue
3661
3646
}
3647
+ tips [k ] = v
3662
3648
}
3663
- return table
3649
+ return & routing. CommandPolicy { Request : req , Response : resp , Tips : tips }
3664
3650
}
3665
3651
3666
3652
//------------------------------------------------------------------------------
0 commit comments