HLen gets the number of fields contained in a hash. It takes a string key 'k' and returns the number of fields in the hash. Parameters: k: The key of the hash table. Returns: int: The number of fields in the hash. error: An error if occurred during the operation, or nil on success.
(key string)
| 534 | // int: The number of fields in the hash. |
| 535 | // error: An error if occurred during the operation, or nil on success. |
| 536 | func (hs *HashStructure) HLen(key string) (int, error) { |
| 537 | // Convert the parameters to bytes |
| 538 | k := stringToBytesWithKey(key) |
| 539 | |
| 540 | // Check the parameters |
| 541 | if len(k) == 0 { |
| 542 | return 0, _const.ErrKeyIsEmpty |
| 543 | } |
| 544 | |
| 545 | // Find the hash metadata by the given key |
| 546 | hashMeta, err := hs.findHashMeta(key, Hash) |
| 547 | if err != nil { |
| 548 | return 0, err |
| 549 | } |
| 550 | |
| 551 | // If the counter is 0, return 0 |
| 552 | if hashMeta.counter == 0 { |
| 553 | return 0, nil |
| 554 | } |
| 555 | |
| 556 | return int(hashMeta.counter), nil |
| 557 | } |
| 558 | |
| 559 | // HUpdate updates the string value of a hash field. |
| 560 | // It takes a string key 'k', a field 'f', and a value 'v' to update the field's value. |
nothing calls this directly
no test coverage detected