Intro
高性能、高可定制的配置管理包,内存键值对管理器
Intro to Store
hedzr/Store provides an extensible, high-performance configuration management library. It is optimized for accessing hierarchical data.
The special is put any data and extract typed it. Which means, the store will try to convert the source data within underlying.
Another feature is the store traces config items' modification states. So you can extract the changed subset. See also Modified State.
The store is designed to provide the basic skeleton for hedzr/cmdr v2 (RC1 released). It also could be used as a standalone config manager. We split the original config (called as option-store at cmdr v1) and rewrote it. In the refactoring phrase, some excellent config-mgmt/centers get many tips to us, such as koanf and viper. Many respects.
The store accesses tree data with a dotted key path, that means you may point to a specified tree node and access it, modify it, monitor it or remove it. You can use a different delimiter char like / or \.
The dumping result looks like (internal data structure):
As you seen, the internal structure will be printed out for the deep researching.

<B> is branch, <L> is leaf.
Leaf node contains data, comment, description and tag (any value).
To speed up the tree, any delimiter char is a part of the path.
The store provides advanced APIs to extract the typed data from some a node,
The searching tools are also used to locate whether a key exists or not:
Locate() is a more friendly Has() test for the developers when they want to inspect more extra information after searching.
For more information, browse these public sites:
- https://pkg.go.dev/github.com/hedzr/store
- https://github.com/hedzr/store
- Check out the codes in test source files
To see the recently changes at CHANGELOG.
Since v1.1.0, unexported struct ptr (*storeS) removed from Store API.
These apis changed to:
Clone() (newStore Store)Dup() (newStore Store)WithPrefix(prefix ...string) (newStore Store)WithPrefixReplaced(newPrefix ...string) (newStore Store)
Since v1.2.0, the prototypes of Locate/Query are changed.
- an extra
kvpairwill be returned if there is:identin trie path and matched ok. - support these url var matching: "/:id/", "/*filepath"
For example, matching /hello/bob on a router path pattern /hello/:name will get kvpair = {"name":"bob"}, and /search/any/thing/here on pattern /search/*keywords will get kvpair = {"keywords":"any/thing/here"}.
Since v1.2.5, SetTTL(path, ttl, callback) added.
Since v1.2.8, SetTTLFast(node, ttl, callback) added.
Since v1.2.8, SetEx(path, val, callback) added.
Since v1.3.0, move the minimal toolchain to go1.23.7.
Using store as the core of a http router is possible. Since v1.2 we added builtin http route param support (like :user).
Using hedzr/store as a in-memory Cache provider is possible. Since v1.2.5 we added SetTTL to reset the data of a node (by key) to zero value. You can inject your codes to drop the key or whatever else.
Benchmarks
The store is designed to reduce the allocations much better, and up the performance much better. We have a zero-allocation implementation in reading a key-value pair, currently.
Our benchmark testing (test/bench_test.go) shows:
Some control groups with the same executive environment produced:
-
To avoid controversy, pkg-name masked.
-
Both of these testing data sets have the same scale basically (lower than 20 keys). Also, the querying words are same.

-
No Warrenties.
The performance benefits mainly from the refresh implemented about our internal Trie-tree (radix-tree).
As an addition, here are huger/larger benches:
You can find out that our store has a better score while working on a large configuration set,
although it might take more latency than on a tiny set.
The datasource of huge test is a pet-store openapi swagger doc, coming from https://editor.swagger.io/.
With a same input like a YAML file, the store could get more key-value pairs because store.WithStoreFlattenSlice(true) applied, which will expand slices and maps in a value as nested key-value pairs.
So that's it.
Dependencies
The store1 imports some modules of mine:
The dependency graph is:
LICENSE
Apache 2.0
Footnotes
-
hedzr/storeis a high-performance configure management library ↩ -
hedzr/evendeepoffers a customizable deepcopy tool to you. There are also deepequal, deepdiff tools in it. ↩ -
hedzr/loggprovides a slog like and colorful logging library ↩ -
hedzr/errors.v3provides some extensions and compatible layer over go1.11 ~ nowadays. ↩ -
hedzr/isis a basic environ detectors library ↩
How is this guide?
Last updated on