@@ -3479,7 +3479,7 @@ type CommandInfo struct {
34793479 LastKeyPos int8
34803480 StepCount int8
34813481 ReadOnly bool
3482- Tips map [ string ] string
3482+ Tips * routing. CommandPolicy
34833483}
34843484
34853485type CommandsInfoCmd struct {
@@ -3612,8 +3612,7 @@ func (cmd *CommandsInfoCmd) readReply(rd *proto.Reader) error {
36123612 return err
36133613 }
36143614
3615- cmdInfo .Tips = make (map [string ]string , tipsLen )
3616-
3615+ rawTips := make (map [string ]string , tipsLen )
36173616 for f := 0 ; f < tipsLen ; f ++ {
36183617 tip , err := rd .ReadString ()
36193618 if err != nil {
@@ -3622,7 +3621,7 @@ func (cmd *CommandsInfoCmd) readReply(rd *proto.Reader) error {
36223621
36233622 // Handle tips that don't have a colon (like "nondeterministic_output")
36243623 if ! strings .Contains (tip , ":" ) {
3625- cmdInfo . Tips [tip ] = ""
3624+ rawTips [tip ] = ""
36263625 continue
36273626 }
36283627
@@ -3631,8 +3630,9 @@ func (cmd *CommandsInfoCmd) readReply(rd *proto.Reader) error {
36313630 if ! ok {
36323631 return fmt .Errorf ("redis: unexpected tip %q in COMMAND reply" , tip )
36333632 }
3634- cmdInfo . Tips [k ] = v
3633+ rawTips [k ] = v
36353634 }
3635+ cmdInfo .Tips = parseCommandPolicies (rawTips )
36363636
36373637 if err := rd .DiscardNext (); err != nil {
36383638 return err
@@ -3684,47 +3684,33 @@ func (c *cmdsInfoCache) Get(ctx context.Context) (map[string]*CommandInfo, error
36843684}
36853685
36863686// ------------------------------------------------------------------------------
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"
37003689
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
37043693
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
37103698 }
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
37153703 }
3716- } else {
3717- return BuiltinPolicies
37183704 }
3719- table [name ] = routing.CommandPolicy {Request : req , Response : resp }
37203705 }
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
37253710 }
3711+ tips [k ] = v
37263712 }
3727- return table
3713+ return & routing. CommandPolicy { Request : req , Response : resp , Tips : tips }
37283714}
37293715
37303716//------------------------------------------------------------------------------
0 commit comments