@@ -3414,7 +3414,7 @@ type CommandInfo struct {
34143414 LastKeyPos int8
34153415 StepCount int8
34163416 ReadOnly bool
3417- Tips map [ string ] string
3417+ Tips * routing. CommandPolicy
34183418}
34193419
34203420type CommandsInfoCmd struct {
@@ -3547,8 +3547,7 @@ func (cmd *CommandsInfoCmd) readReply(rd *proto.Reader) error {
35473547 return err
35483548 }
35493549
3550- cmdInfo .Tips = make (map [string ]string , tipsLen )
3551-
3550+ rawTips := make (map [string ]string , tipsLen )
35523551 for f := 0 ; f < tipsLen ; f ++ {
35533552 tip , err := rd .ReadString ()
35543553 if err != nil {
@@ -3557,7 +3556,7 @@ func (cmd *CommandsInfoCmd) readReply(rd *proto.Reader) error {
35573556
35583557 // Handle tips that don't have a colon (like "nondeterministic_output")
35593558 if ! strings .Contains (tip , ":" ) {
3560- cmdInfo . Tips [tip ] = ""
3559+ rawTips [tip ] = ""
35613560 continue
35623561 }
35633562
@@ -3566,8 +3565,9 @@ func (cmd *CommandsInfoCmd) readReply(rd *proto.Reader) error {
35663565 if ! ok {
35673566 return fmt .Errorf ("redis: unexpected tip %q in COMMAND reply" , tip )
35683567 }
3569- cmdInfo . Tips [k ] = v
3568+ rawTips [k ] = v
35703569 }
3570+ cmdInfo .Tips = parseCommandPolicies (rawTips )
35713571
35723572 if err := rd .DiscardNext (); err != nil {
35733573 return err
@@ -3620,47 +3620,33 @@ func (c *cmdsInfoCache) Get(ctx context.Context) (map[string]*CommandInfo, error
36203620}
36213621
36223622// ------------------------------------------------------------------------------
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"
36363625
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
36403629
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
36463634 }
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
36513639 }
3652- } else {
3653- return BuiltinPolicies
36543640 }
3655- table [name ] = routing.CommandPolicy {Request : req , Response : resp }
36563641 }
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
36613646 }
3647+ tips [k ] = v
36623648 }
3663- return table
3649+ return & routing. CommandPolicy { Request : req , Response : resp , Tips : tips }
36643650}
36653651
36663652//------------------------------------------------------------------------------
0 commit comments