liboffkv ======== [![License](https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Travis CI](http://badges.herokuapp.com/travis/offscale/liboffkv?branch=master&label=OSX&env=BADGE=osx&style=flat-square)](https://travis-ci.org/offscale/liboffkv) [![Travis CI](http://badges.herokuapp.com/travis/offscale/liboffkv?branch=master&label=Linux&env=BADGE=linux&style=flat-square)](https://travis-ci.org/offscale/liboffkv) #### The library is designed to provide a uniform interface for three distributed KV storages: etcd, ZooKeeper and Consul. The services have similar but different data models, so we outlined the common features. In our implementation, keys form a ZK-like hierarchy. Each key has a version that is int64 number greater than 0. Current version is returned with other data by the most of operations. All the operations supported are listed below.
Method | Parameters | Description |
---|---|---|
create |
key: string value: char[] leased: bool (=false) -- makes the key to be deleted on client disconnect |
Creates the key. Throws an exception if the key already exists or preceding entry does not exist. Returns: version of the newly created key. |
set | key: string value: char[] |
Assigns the value. Creates the key if it doesn’t exist. Throws an exception if preceding entry does not exist. Returns: new version of the key. |
cas | key: string value: char[] version: int64 (=0) -- expected version of the key |
Compare and set operation. If the key does not exist and the version passed equals 0, creates it. Throws an exception if preceding entry does not exist. If the key exists and its version equals to specified one updates the value. Otherwise does nothing and returns 0. Returns: new version of the key or 0. |
get | key: string watch: bool (=false) -- start watching for change in value |
Returns the value currently assigned to the key. Throws an exception if the key does not exist. If watch is true, creates WatchHandler waiting for a change in value. (see usage example below). Returns: current value and WatchHandler. |
exists | key: string watch: bool (=false) -- start watching for removal or creation of the key |
Checks if the key exists. If watch is true, creates WatchHandler waiting for a change in state of existance (see usage example below). Returns: version of the key or 0 if it doesn't exist and WatchHandler. |
get_children | key: string watch: bool (=false) |
Returns a list of the key's direct children. Throws an exception if the key does not exist. If watch is true, creates WatchHandler waiting for any changes among the children. Returns: list of direct children and WatchHandler. |
erase | key: string version: int64 (=0) |
Erases the key and all its descendants if the version given equals to the current key's version. Does it unconditionally if version is 0. Throws an exception if the key does not exist. Returns: (void) |
commit | transaction: Transaction | Commits transaction (see transactions API below). If it was failed, throws TxnFailed with an index of the failed operation. Returns: list of new versions of keys affected by the transaction |
Method | Parameters | Description |
---|---|---|
create |
key: string value: char[] leased: bool (=false) |
Creates the key. Rolls back if the key already exists or preceding entry does not exist. |
set | key: string value: char[] |
Set the value. Rolls back if the key does not exist. n.b behaviors of transaction set and ordinary set differ |
erase | key: string version: int64 (=0) |
Erases the key and all its descendants if the version passed equals to the current key's version. Does it unconditionally if the version is 0. Rolls back if the key does not exist. |
check | key: string version: int64 |
Checks if the given key has the specified version. Only checks if it exists if the version is 0 |