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

Function IncrBy

command/strings.go:395–414  ·  view source on GitHub ↗

IncrBy increments the integer value of a key by the given amount

(ctx *Context, txn *db.Transaction)

Source from the content-addressed store, hash-verified

393
394// IncrBy increments the integer value of a key by the given amount
395func 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
417func IncrByFloat(ctx *Context, txn *db.Transaction) (OnCommit, error) {

Callers

nothing calls this directly

Calls 4

IntegerFunction · 0.85
IncrMethod · 0.80
ErrorMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected