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

Function Incr

command/strings.go:378–392  ·  view source on GitHub ↗

Incr increments the integer value of a key by one

(ctx *Context, txn *db.Transaction)

Source from the content-addressed store, hash-verified

376
377// Incr increments the integer value of a key by one
378func Incr(ctx *Context, txn *db.Transaction) (OnCommit, error) {
379 key := []byte(ctx.Args[0])
380 str, err := txn.String(key)
381 if err != nil {
382 if err == db.ErrTypeMismatch {
383 return nil, ErrTypeMismatch
384 }
385 return nil, errors.New("ERR " + err.Error())
386 }
387 delta, err := str.Incr(1)
388 if err != nil {
389 return nil, errors.New("ERR " + err.Error())
390 }
391 return Integer(ctx.Out, int64(delta)), nil
392}
393
394// IncrBy increments the integer value of a key by the given amount
395func IncrBy(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