IncrByFloat increments the float value of a key by the given amount
(ctx *Context, txn *db.Transaction)
| 415 | |
| 416 | // IncrByFloat increments the float value of a key by the given amount |
| 417 | func IncrByFloat(ctx *Context, txn *db.Transaction) (OnCommit, error) { |
| 418 | key := []byte(ctx.Args[0]) |
| 419 | str, err := txn.String([]byte(key)) |
| 420 | if err != nil { |
| 421 | if err == db.ErrTypeMismatch { |
| 422 | return nil, ErrTypeMismatch |
| 423 | } |
| 424 | return nil, errors.New("ERR " + err.Error()) |
| 425 | } |
| 426 | delta, err := strconv.ParseFloat(ctx.Args[1], 64) |
| 427 | if err != nil { |
| 428 | return nil, ErrInteger |
| 429 | } |
| 430 | delta, err = str.Incrf(delta) |
| 431 | if err != nil { |
| 432 | return nil, errors.New("ERR " + err.Error()) |
| 433 | } |
| 434 | return BulkString(ctx.Out, strconv.FormatFloat(delta, 'f', 17, 64)), nil |
| 435 | } |
| 436 | |
| 437 | // Decr decrements the integer value of a key by one |
| 438 | func Decr(ctx *Context, txn *db.Transaction) (OnCommit, error) { |
nothing calls this directly
no test coverage detected