Keys will return all keys, filtering out any duplicates.
(opts ...WatchOpt)
| 873 | |
| 874 | // Keys will return all keys, filtering out any duplicates. |
| 875 | func (kv *kvs) Keys(opts ...WatchOpt) ([]string, error) { |
| 876 | opts = append(opts, IgnoreDeletes(), MetaOnly()) |
| 877 | watcher, err := kv.WatchAll(opts...) |
| 878 | if err != nil { |
| 879 | return nil, err |
| 880 | } |
| 881 | defer watcher.Stop() |
| 882 | |
| 883 | var keys []string |
| 884 | for entry := range watcher.Updates() { |
| 885 | if entry == nil { |
| 886 | break |
| 887 | } |
| 888 | keys = append(keys, entry.Key()) |
| 889 | } |
| 890 | if len(keys) == 0 { |
| 891 | return nil, ErrNoKeysFound |
| 892 | } |
| 893 | slices.Sort(keys) |
| 894 | return slices.Compact(keys), nil |
| 895 | } |
| 896 | |
| 897 | type keyLister struct { |
| 898 | watcher KeyWatcher |