@@ -319,37 +319,67 @@ func (cmd *BFInfoCmd) Result() (BFInfo, error) {
319319}
320320
321321func (cmd * BFInfoCmd ) readReply (rd * proto.Reader ) (err error ) {
322- n , err := rd .ReadMapLen ()
322+ result := BFInfo {}
323+
324+ readAndAssignValue := func (key string ) error {
325+ switch key {
326+ case "Capacity" , "CAPACITY" :
327+ if result .Capacity , err = rd .ReadInt (); err != nil {
328+ return err
329+ }
330+ case "Size" , "SIZE" :
331+ if result .Size , err = rd .ReadInt (); err != nil {
332+ return err
333+ }
334+ case "Number of filters" , "FILTERS" :
335+ if result .Filters , err = rd .ReadInt (); err != nil {
336+ return err
337+ }
338+ case "Number of items inserted" , "ITEMS" :
339+ if result .ItemsInserted , err = rd .ReadInt (); err != nil {
340+ return err
341+ }
342+ case "Expansion rate" , "EXPANSION" :
343+ if result .ExpansionRate , err = rd .ReadInt (); err != nil {
344+ return err
345+ }
346+ default :
347+ return fmt .Errorf ("redis: BLOOM.INFO unexpected key %s" , key )
348+ }
349+ return nil
350+ }
351+
352+ readType , err := rd .PeekReplyType ()
323353 if err != nil {
324354 return err
325355 }
326356
327- var key string
328- var result BFInfo
329- for f := 0 ; f < n ; f ++ {
330- key , err = rd .ReadString ()
357+ if len (cmd .args ) > 2 && readType == proto .RespArray {
358+ n , err := rd .ReadArrayLen ()
331359 if err != nil {
332360 return err
333361 }
334-
335- switch key {
336- case "Capacity" :
337- result .Capacity , err = rd .ReadInt ()
338- case "Size" :
339- result .Size , err = rd .ReadInt ()
340- case "Number of filters" :
341- result .Filters , err = rd .ReadInt ()
342- case "Number of items inserted" :
343- result .ItemsInserted , err = rd .ReadInt ()
344- case "Expansion rate" :
345- result .ExpansionRate , err = rd .ReadInt ()
346- default :
347- return fmt .Errorf ("redis: BLOOM.INFO unexpected key %s" , key )
362+ if key , ok := cmd .args [2 ].(string ); ok && n == 1 {
363+ if err := readAndAssignValue (key ); err != nil {
364+ return err
365+ }
366+ } else {
367+ return fmt .Errorf ("redis: BLOOM.INFO invalid argument key type" )
348368 }
349-
369+ } else {
370+ n , err := rd .ReadMapLen ()
350371 if err != nil {
351372 return err
352373 }
374+ for i := 0 ; i < n ; i ++ {
375+ key , err := rd .ReadString ()
376+ if err != nil {
377+ return err
378+ }
379+ if err := readAndAssignValue (key ); err != nil {
380+ return err
381+ }
382+ }
353383 }
354384
355385 cmd .val = result
0 commit comments