IncrBy increments the integer value of a key by the given amount
(ctx *Context, txn *db.Transaction)
| 393 | |
| 394 | // IncrBy increments the integer value of a key by the given amount |
| 395 | func IncrBy(ctx *Context, txn *db.Transaction) (OnCommit, error) { |
| 396 | key := []byte(ctx.Args[0]) |
| 397 | str, err := txn.String(key) |
| 398 | if err != nil { |
| 399 | if err == db.ErrTypeMismatch { |
| 400 | return nil, ErrTypeMismatch |
| 401 | } |
| 402 | return nil, errors.New("ERR " + err.Error()) |
| 403 | } |
| 404 | delta, err := strconv.ParseInt(ctx.Args[1], 10, 0) |
| 405 | if err != nil { |
| 406 | return nil, ErrInteger |
| 407 | } |
| 408 | |
| 409 | delta, err = str.Incr(delta) |
| 410 | if err != nil { |
| 411 | return nil, errors.New("ERR " + err.Error()) |
| 412 | } |
| 413 | return Integer(ctx.Out, int64(delta)), nil |
| 414 | } |
| 415 | |
| 416 | // IncrByFloat increments the float value of a key by the given amount |
| 417 | func IncrByFloat(ctx *Context, txn *db.Transaction) (OnCommit, error) { |