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

Function Decr

command/strings.go:438–453  ·  view source on GitHub ↗

Decr decrements the integer value of a key by one

(ctx *Context, txn *db.Transaction)

Source from the content-addressed store, hash-verified

436
437// Decr decrements the integer value of a key by one
438func Decr(ctx *Context, txn *db.Transaction) (OnCommit, error) {
439 key := []byte(ctx.Args[0])
440 str, err := txn.String(key)
441 if err != nil {
442 if err == db.ErrTypeMismatch {
443 return nil, ErrTypeMismatch
444 }
445 return nil, errors.New("ERR " + err.Error())
446 }
447
448 delta, err := str.Incr(-1)
449 if err != nil {
450 return nil, errors.New("ERR " + err.Error())
451 }
452 return Integer(ctx.Out, int64(delta)), nil
453}
454
455// DecrBy decrements the integer value of a key by the given number
456func DecrBy(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