MCPcopy
hub / github.com/nats-io/nats.go / Update

Method Update

kv.go:729–749  ·  view source on GitHub ↗

Update will update the value if the latest revision matches.

(key string, value []byte, revision uint64)

Source from the content-addressed store, hash-verified

727
728// Update will update the value if the latest revision matches.
729func (kv *kvs) Update(key string, value []byte, revision uint64) (uint64, error) {
730 if !keyValid(key) {
731 return 0, ErrInvalidKey
732 }
733
734 var b strings.Builder
735 if kv.useJSPfx {
736 b.WriteString(kv.js.opts.pre)
737 }
738 b.WriteString(kv.pre)
739 b.WriteString(key)
740
741 m := Msg{Subject: b.String(), Header: Header{}, Data: value}
742 m.Header.Set(ExpectedLastSubjSeqHdr, strconv.FormatUint(revision, 10))
743
744 pa, err := kv.js.PublishMsg(&m)
745 if err != nil {
746 return 0, err
747 }
748 return pa.Sequence, err
749}
750
751// Delete will place a delete marker and leave all revisions.
752func (kv *kvs) Delete(key string, opts ...DeleteOpt) error {

Callers 1

CreateMethod · 0.95

Calls 4

keyValidFunction · 0.70
SetMethod · 0.65
PublishMsgMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected