nats-io / nats.go

Golang client for NATS, the cloud native messaging system.
https://nats.io
Apache License 2.0
5.36k stars 679 forks source link

Add `KeysWithFilter` methods to KV interface #1655

Open Jarema opened 1 month ago

Jarema commented 1 month ago

Proposed change

// KeysWithFilters returns a filtered list of keys in the bucket.
KeysWithFilters(filter []string) ([]string, error)

// And for the new, iterable API:
ListKeysWithFilters(filter []string) (KeyLister, error)
    // KeysWithFilters returns a filtered list of keys in the bucket.
    // Historically this method returned a complete slice of all keys in the bucket,
    // however clients should return interable result.
    // Languages can implement the list of filters in most idiomatic way - as an iterator, variadic argument, slice, etc.
    // When multiple filters are passed, client library should check `consumer info` from `consumer create method` if the filters are matching,
    // as nats-server < 2.10 would ignore them.
    KeysWithFilters(filter []string) ([]string, error)

We have two separate functions for single and multiple filters, as multiple filters requires server 2.10

reference ADR: https://github.com/nats-io/nats-architecture-and-design/blob/main/adr/ADR-8.md?plain=1#L139 reference ADR issue: https://github.com/nats-io/nats-architecture-and-design/issues/289

Use case

https://github.com/nats-io/nats-server/issues/5540

Contribution

No response

ripienaar commented 1 month ago

In the case of go at least, wouldnt a WatchOpt be better? These commands already take those.

Darshan174 commented 1 month ago

Hey please checkout PR #1658, any suggestion would be helpful.

aditya7302 commented 1 month ago

@Jarema is this issue still open. I would like to work on this. Please assign me this issue.