DecrBy decrements the integer value of a key by the given number
(ctx *Context, txn *db.Transaction)
| 454 | |
| 455 | // DecrBy decrements the integer value of a key by the given number |
| 456 | func DecrBy(ctx *Context, txn *db.Transaction) (OnCommit, error) { |
| 457 | key := []byte(ctx.Args[0]) |
| 458 | str, err := txn.String(key) |
| 459 | if err != nil { |
| 460 | if err == db.ErrTypeMismatch { |
| 461 | return nil, ErrTypeMismatch |
| 462 | } |
| 463 | return nil, errors.New("ERR " + err.Error()) |
| 464 | } |
| 465 | delta, err := strconv.ParseInt(ctx.Args[1], 10, 64) |
| 466 | if err != nil { |
| 467 | return nil, ErrInteger |
| 468 | } |
| 469 | |
| 470 | delta, err = str.Incr(-delta) |
| 471 | if err != nil { |
| 472 | return nil, errors.New("ERR " + err.Error()) |
| 473 | } |
| 474 | return Integer(ctx.Out, int64(delta)), nil |
| 475 | } |
| 476 | |
| 477 | // SetBit sets or clears the bit at offset in the string value stored at key. |
| 478 | func SetBit(ctx *Context, txn *db.Transaction) (OnCommit, error) { |