MCPcopy Create free account
hub / github.com/nutsdb/nutsdb / integerIncr

Method integerIncr

tx_btree.go:561–582  ·  view source on GitHub ↗
(bucket string, key []byte, increment int64)

Source from the content-addressed store, hash-verified

559}
560
561func (tx *Tx) integerIncr(bucket string, key []byte, increment int64) error {
562 return tx.update(bucket, key, func(value []byte) ([]byte, error) {
563 intValue, err := strconv2.StrToInt64(string(value))
564
565 if err != nil && errors.Is(err, strconv.ErrRange) {
566 return []byte(bigIntIncr(string(value), strconv2.Int64ToStr(increment))), nil
567 }
568
569 if err != nil {
570 return nil, ErrValueNotInteger
571 }
572
573 if (increment > 0 && math.MaxInt64-increment < intValue) || (increment < 0 && math.MinInt64-increment > intValue) {
574 return []byte(bigIntIncr(string(value), strconv2.Int64ToStr(increment))), nil
575 }
576
577 atomic.AddInt64(&intValue, increment)
578 return []byte(strconv2.Int64ToStr(intValue)), nil
579 }, func(oldTTL uint32) (uint32, error) {
580 return oldTTL, nil
581 })
582}
583
584func (tx *Tx) Incr(bucket string, key []byte) error {
585 return tx.integerIncr(bucket, key, 1)

Callers 4

IncrMethod · 0.95
DecrMethod · 0.95
IncrByMethod · 0.95
DecrByMethod · 0.95

Calls 2

updateMethod · 0.95
bigIntIncrFunction · 0.85

Tested by

no test coverage detected