HStrLen returns the string length of the value associated with a field in the hash. It takes a string key 'k' and a field 'f' and returns the length of the field's value. Parameters: k: The key of the hash table. f: The field whose value length needs to be determined. Returns: int: The length
(key string, field interface{})
| 894 | // int: The length of the field's value. |
| 895 | // error: An error if occurred during the operation, or nil on success. |
| 896 | func (hs *HashStructure) HStrLen(key string, field interface{}) (int, error) { |
| 897 | // Convert the parameters to bytes |
| 898 | k := stringToBytesWithKey(key) |
| 899 | |
| 900 | // Convert the parameters to bytes |
| 901 | f, err, _ := interfaceToBytes(field) |
| 902 | if err != nil { |
| 903 | return 0, err |
| 904 | } |
| 905 | |
| 906 | // Check the parameters |
| 907 | if len(k) == 0 || len(f) == 0 { |
| 908 | return 0, _const.ErrKeyIsEmpty |
| 909 | } |
| 910 | |
| 911 | // Find the hash metadata by the given key |
| 912 | hashMeta, err := hs.findHashMeta(key, Hash) |
| 913 | if err != nil { |
| 914 | return 0, err |
| 915 | } |
| 916 | |
| 917 | // If the counter is 0, return 0 |
| 918 | if hashMeta.counter == 0 { |
| 919 | return 0, nil |
| 920 | } |
| 921 | |
| 922 | // Create a new HashField |
| 923 | hf := &HashField{ |
| 924 | field: f, |
| 925 | key: k, |
| 926 | version: hashMeta.version, |
| 927 | } |
| 928 | |
| 929 | // Encode the HashField |
| 930 | hfBuf := hf.encodeHashField() |
| 931 | |
| 932 | // Get the field from the database |
| 933 | value, err := hs.db.Get(hfBuf) |
| 934 | if err != nil && err == _const.ErrKeyNotFound { |
| 935 | return 0, nil |
| 936 | } |
| 937 | |
| 938 | return len(value), nil |
| 939 | } |
| 940 | |
| 941 | // HMove moves a field from a source hash to a destination hash. |
| 942 | // It takes the source key 'source', the destination key 'destination', and the field 'f' to be moved. |
nothing calls this directly
no test coverage detected