MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / cmdDECR

Function cmdDECR

strings.go:486–517  ·  view source on GitHub ↗
(m uhaha.Machine, args []string)

Source from the content-addressed store, hash-verified

484 return redcon.SimpleInt(n), nil
485}
486
487func cmdDECR(m uhaha.Machine, args []string) (interface{}, error) {
488 // 1. Validate the number of arguments
489 if len(args) != 2 {
490 return nil, uhaha.ErrWrongNumArgs
491 }
492
493 // 2. Get the key name
494 key := []byte(args[1])
495
496 // 3. Check if the key exists
497 exists, err := ldb.Exists(key)
498 if err != nil {
499 return nil, err
500 }
501
502 // 4. If the key does not exist, set its value to 0
503 if exists == 0 {
504 if err := ldb.Set(key, []byte("0")); err != nil {
505 return nil, err
506 }
507 }
508
509 // 5. Perform the decrement operation
510 n, err := ldb.Decr(key)
511 if err != nil {
512 // 6. If the key's value is not an integer or cannot be represented as a 64-bit signed integer, return an error
513 return nil, err
514 }
515
516 // 7. Return the value after decrementing
517 return redcon.SimpleInt(n), nil
518}
519
520func cmdBITPOS(m uhaha.Machine, args []string) (interface{}, error) {

Callers

nothing calls this directly

Calls 1

SetMethod · 0.80

Tested by

no test coverage detected