Decr decrements the integer value of a key by one
(ctx *Context, txn *db.Transaction)
| 436 | |
| 437 | // Decr decrements the integer value of a key by one |
| 438 | func Decr(ctx *Context, txn *db.Transaction) (OnCommit, error) { |
| 439 | key := []byte(ctx.Args[0]) |
| 440 | str, err := txn.String(key) |
| 441 | if err != nil { |
| 442 | if err == db.ErrTypeMismatch { |
| 443 | return nil, ErrTypeMismatch |
| 444 | } |
| 445 | return nil, errors.New("ERR " + err.Error()) |
| 446 | } |
| 447 | |
| 448 | delta, err := str.Incr(-1) |
| 449 | if err != nil { |
| 450 | return nil, errors.New("ERR " + err.Error()) |
| 451 | } |
| 452 | return Integer(ctx.Out, int64(delta)), nil |
| 453 | } |
| 454 | |
| 455 | // DecrBy decrements the integer value of a key by the given number |
| 456 | func DecrBy(ctx *Context, txn *db.Transaction) (OnCommit, error) { |