diff --git a/kv.go b/kv.go index 58f4b4b95..deaefde2a 100644 --- a/kv.go +++ b/kv.go @@ -112,6 +112,8 @@ type watchOpts struct { ignoreDeletes bool // Include all history per subject, not just last one. includeHistory bool + // retrieve only the meta data of the entry + metaOnly bool } type watchOptFn func(opts *watchOpts) error @@ -136,6 +138,14 @@ func IgnoreDeletes() WatchOpt { }) } +// MetaOnly instructs the key watcher to retrieve only the entry meta data, not the entry value +func MetaOnly() WatchOpt { + return watchOptFn(func(opts *watchOpts) error { + opts.metaOnly = true + return nil + }) +} + // KeyValueConfig is for configuring a KeyValue store. type KeyValueConfig struct { Bucket string @@ -534,7 +544,7 @@ func (kv *kvs) PurgeDeletes(opts ...WatchOpt) error { // Keys() will return all keys. func (kv *kvs) Keys(opts ...WatchOpt) ([]string, error) { - opts = append(opts, IgnoreDeletes()) + opts = append(opts, IgnoreDeletes(), MetaOnly()) watcher, err := kv.WatchAll(opts...) if err != nil { return nil, err @@ -676,6 +686,9 @@ func (kv *kvs) Watch(keys string, opts ...WatchOpt) (KeyWatcher, error) { if !o.includeHistory { subOpts = append(subOpts, DeliverLastPerSubject()) } + if o.metaOnly { + subOpts = append(subOpts, HeadersOnly()) + } sub, err := kv.js.Subscribe(keys, update, subOpts...) if err != nil { return nil, err