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

Method KeyValue

kv.go:374–396  ·  view source on GitHub ↗

KeyValue will lookup and bind to an existing KeyValue store.

(bucket string)

Source from the content-addressed store, hash-verified

372
373// KeyValue will lookup and bind to an existing KeyValue store.
374func (js *js) KeyValue(bucket string) (KeyValue, error) {
375 if !js.nc.serverMinVersion(2, 6, 2) {
376 return nil, errors.New("nats: key-value requires at least server version 2.6.2")
377 }
378 if !bucketValid(bucket) {
379 return nil, ErrInvalidBucketName
380 }
381 stream := fmt.Sprintf(kvBucketNameTmpl, bucket)
382 si, err := js.StreamInfo(stream)
383 if err != nil {
384 if errors.Is(err, ErrStreamNotFound) {
385 err = ErrBucketNotFound
386 }
387 return nil, err
388 }
389 // Do some quick sanity checks that this is a correctly formed stream for KV.
390 // Max msgs per subject should be > 0.
391 if si.Config.MaxMsgsPerSubject < 1 {
392 return nil, ErrBadBucket
393 }
394
395 return mapStreamToKVS(js, si), nil
396}
397
398// CreateKeyValue will create a KeyValue store with the following configuration.
399func (js *js) CreateKeyValue(cfg *KeyValueConfig) (KeyValue, error) {

Callers

nothing calls this directly

Calls 5

StreamInfoMethod · 0.95
serverMinVersionMethod · 0.80
bucketValidFunction · 0.70
mapStreamToKVSFunction · 0.70
IsMethod · 0.45

Tested by

no test coverage detected