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

Method update

tx_btree.go:511–533  ·  view source on GitHub ↗
(bucket string, key []byte, getNewValue func([]byte) ([]byte, error), getNewTTL func(uint32) (uint32, error))

Source from the content-addressed store, hash-verified

509}
510
511func (tx *Tx) update(bucket string, key []byte, getNewValue func([]byte) ([]byte, error), getNewTTL func(uint32) (uint32, error)) error {
512 return tx.tryGet(bucket, key, func(record *core.Record, pendingEntry *core.Entry, found bool, bucketId core.BucketId) error {
513 if !found {
514 return ErrKeyNotFound
515 }
516
517 value, ttl, err := tx.loadValue(record, pendingEntry)
518 if err != nil {
519 return err
520 }
521
522 newValue, err := getNewValue(value)
523 if err != nil {
524 return err
525 }
526
527 newTTL, err := getNewTTL(ttl)
528 if err != nil {
529 return err
530 }
531 return tx.put(bucket, key, newValue, newTTL, DataSetFlag, uint64(tx.db.ttlService.NowMillis()), DataStructureBTree)
532 })
533}
534
535func (tx *Tx) updateOrPut(bucket string, key, value []byte, getUpdatedValue func([]byte) ([]byte, error)) error {
536 return tx.tryGet(bucket, key, func(record *core.Record, pendingEntry *core.Entry, found bool, bucketId core.BucketId) error {

Callers 6

PutIfExistsMethod · 0.95
GetSetMethod · 0.95
integerIncrMethod · 0.95
PersistMethod · 0.95
TestTx_NewTTLReturnErrorFunction · 0.80

Calls 4

tryGetMethod · 0.95
loadValueMethod · 0.95
putMethod · 0.95
NowMillisMethod · 0.65

Tested by 2

TestTx_NewTTLReturnErrorFunction · 0.64