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

Function DecrBy

command/strings.go:456–475  ·  view source on GitHub ↗

DecrBy decrements the integer value of a key by the given number

(ctx *Context, txn *db.Transaction)

Source from the content-addressed store, hash-verified

454
455// DecrBy decrements the integer value of a key by the given number
456func DecrBy(ctx *Context, txn *db.Transaction) (OnCommit, error) {
457 key := []byte(ctx.Args[0])
458 str, err := txn.String(key)
459 if err != nil {
460 if err == db.ErrTypeMismatch {
461 return nil, ErrTypeMismatch
462 }
463 return nil, errors.New("ERR " + err.Error())
464 }
465 delta, err := strconv.ParseInt(ctx.Args[1], 10, 64)
466 if err != nil {
467 return nil, ErrInteger
468 }
469
470 delta, err = str.Incr(-delta)
471 if err != nil {
472 return nil, errors.New("ERR " + err.Error())
473 }
474 return Integer(ctx.Out, int64(delta)), nil
475}
476
477// SetBit sets or clears the bit at offset in the string value stored at key.
478func SetBit(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