| 509 | } |
| 510 | |
| 511 | func (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 | |
| 535 | func (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 { |