@@ -321,31 +321,33 @@ func (cmd *BFInfoCmd) Result() (BFInfo, error) {
321321func (cmd * BFInfoCmd ) readReply (rd * proto.Reader ) (err error ) {
322322 result := BFInfo {}
323323
324+ // Create a mapping from key names to pointers of struct fields
325+ respMapping := map [string ]* int64 {
326+ "Capacity" : & result .Capacity ,
327+ "CAPACITY" : & result .Capacity ,
328+ "Size" : & result .Size ,
329+ "SIZE" : & result .Size ,
330+ "Number of filters" : & result .Filters ,
331+ "FILTERS" : & result .Filters ,
332+ "Number of items inserted" : & result .ItemsInserted ,
333+ "ITEMS" : & result .ItemsInserted ,
334+ "Expansion rate" : & result .ExpansionRate ,
335+ "EXPANSION" : & result .ExpansionRate ,
336+ }
337+
338+ // Helper function to read and assign a value based on the key
324339 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 :
340+ fieldPtr , exists := respMapping [key ]
341+ if ! exists {
347342 return fmt .Errorf ("redis: BLOOM.INFO unexpected key %s" , key )
348343 }
344+
345+ // Read the integer and assign to the field via pointer dereferencing
346+ val , err := rd .ReadInt ()
347+ if err != nil {
348+ return err
349+ }
350+ * fieldPtr = val
349351 return nil
350352 }
351353
0 commit comments