HDelAll deletes all fields from a hash. It takes a string key 'k' to be deleted from the hash. It returns a boolean indicating the success of the operation and any possible error. Parameters: k: The key of the hash table. Returns: bool: True if the hash was deleted successfully, false otherwis
(key string)
| 381 | // bool: True if the hash was deleted successfully, false otherwise. |
| 382 | // error: An error if occurred during the operation, or nil on success. |
| 383 | func (hs *HashStructure) HDelAll(key string) (bool, error) { |
| 384 | // Convert the parameters to bytes |
| 385 | k := stringToBytesWithKey(key) |
| 386 | |
| 387 | // Check the parameters |
| 388 | if len(k) == 0 { |
| 389 | return false, _const.ErrKeyIsEmpty |
| 390 | } |
| 391 | |
| 392 | // Find the hash metadata by the given key |
| 393 | hashMeta, err := hs.findHashMeta(key, Hash) |
| 394 | if err != nil { |
| 395 | return false, err |
| 396 | } |
| 397 | |
| 398 | // If the counter is 0, return false |
| 399 | if hashMeta.counter == 0 { |
| 400 | return false, nil |
| 401 | } |
| 402 | |
| 403 | // Create a new write batch |
| 404 | batch := hs.db.NewWriteBatch(config.DefaultWriteBatchOptions) |
| 405 | |
| 406 | // Delete the field from the database |
| 407 | _ = batch.Delete(k) |
| 408 | |
| 409 | // Commit the write batch |
| 410 | err = batch.Commit() |
| 411 | if err != nil { |
| 412 | return false, err |
| 413 | } |
| 414 | |
| 415 | return true, nil |
| 416 | } |
| 417 | |
| 418 | // HExpire sets a timeout on a hash. |
| 419 | // It takes a string key 'k' and a duration 'ttl' to set the timeout. |
nothing calls this directly
no test coverage detected