Incr increments the integer value of a key by one
(ctx *Context, txn *db.Transaction)
| 376 | |
| 377 | // Incr increments the integer value of a key by one |
| 378 | func Incr(ctx *Context, txn *db.Transaction) (OnCommit, error) { |
| 379 | key := []byte(ctx.Args[0]) |
| 380 | str, err := txn.String(key) |
| 381 | if err != nil { |
| 382 | if err == db.ErrTypeMismatch { |
| 383 | return nil, ErrTypeMismatch |
| 384 | } |
| 385 | return nil, errors.New("ERR " + err.Error()) |
| 386 | } |
| 387 | delta, err := str.Incr(1) |
| 388 | if err != nil { |
| 389 | return nil, errors.New("ERR " + err.Error()) |
| 390 | } |
| 391 | return Integer(ctx.Out, int64(delta)), nil |
| 392 | } |
| 393 | |
| 394 | // IncrBy increments the integer value of a key by the given amount |
| 395 | func IncrBy(ctx *Context, txn *db.Transaction) (OnCommit, error) { |