libkv
is a unified library to interact with different key-value store backends. libkv
was originally part of Docker Swarm v1 in the very first versions of the development. Later, all code related to key-value store discovery services was refactored and moved to www.github.com/docker/libkv.
libkv
allows you to execute CRUD operations and also to watch key-value entries from different backends, so we can use the same code to work with all HA distributed key-value stores, which are Consul, Etcd, and ZooKeeper as shown in the following figure. At the time of writing, libkv also supports a local store implemented using BoltDB.
To start with libkv,
we need to understand how to call its APIs first. Here's the libkv Store
interface in Go, for every store implementation:
type Store interface { Put(key string, value []byte, options *WriteOptions) error Get(key string) (*KVPair, error) Delete(key string) error Exists(key string) (bool, error) Watch(key string, stopCh...