MCPcopy Create free account
hub / github.com/distributedio/titan / IncrByFloat

Function IncrByFloat

command/strings.go:417–435  ·  view source on GitHub ↗

IncrByFloat increments the float value of a key by the given amount

(ctx *Context, txn *db.Transaction)

Source from the content-addressed store, hash-verified

415
416// IncrByFloat increments the float value of a key by the given amount
417func 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
438func Decr(ctx *Context, txn *db.Transaction) (OnCommit, error) {

Callers

nothing calls this directly

Calls 4

BulkStringFunction · 0.85
IncrfMethod · 0.80
ErrorMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected