GetFields returns a list of all field names in the hash stored at the specified key. It takes a string key 'k' and returns a slice of strings representing the field names and any possible error. Parameters: k: The key of the hash table. Returns: []string: A list of field names in the hash.
(key string)
| 1208 | // |
| 1209 | // []string: A list of field names in the hash. |
| 1210 | func (hs *HashStructure) GetFields(key string) []string { |
| 1211 | // Get all the keys from the database |
| 1212 | byte_keys := hs.db.GetListKeys() |
| 1213 | |
| 1214 | // Create a new slice of strings |
| 1215 | fields := make([]string, 0) |
| 1216 | |
| 1217 | for _, k := range byte_keys { |
| 1218 | // Check if the key has the identifier suffix |
| 1219 | if keysIdentify(k) { |
| 1220 | hf, _ := decodeHashField(k) |
| 1221 | if string(hf.key) == key { |
| 1222 | fields = append(fields, string(hf.field)) |
| 1223 | } |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | return fields |
| 1228 | } |
| 1229 | |
| 1230 | // HGetAllFieldAndValue returns all fields and values of the hash stored at the specified key. |
| 1231 | // It takes a string key 'k' and returns a map of strings representing the field names and |