Functions |
Boolean | append (String key, Array values, Function|Undefined callback) |
| Append values to the list for the specified key.
|
Number | clear (Function|Undefined callback) |
| Delete all stored entries.
|
Number | dequeue (String key, Integer|Undefined count, Function|Undefined callback) |
| Dequeues the number of values from the list for the specified key.
|
Number | destroy (Function|Undefined callback) |
| Deallocate native resources used for this store.
|
Object | entries (Function|Undefined callback) |
| All the entries from this store.
|
Any | get (String key, Function|Undefined callback) |
| Get an element from the store.
|
Object | getBatch (Array keyList, Function|Undefined callback) |
| Get multiple elements from the store.
|
Array | keys (Function|Undefined callback) |
| All the keys from this store.
|
Object | KVStore (String|Undefined|Number filePathOrHandle, Function|Undefined callback) |
| Create KVStore instance.
|
Number | persist (Function|Undefined callback) |
| Save all contents to file.
|
Any | put (String key, Object|Array value, Function|Undefined callback) |
| Put an element to the store.
|
Object | putBatch (Object obj, Function|Undefined callback) |
| Put multiple elements to the store.
|
Boolean | remove (String key, Function|Undefined callback) |
| Remove an element from the store.
|
Array | removeBatch (Array keyList, Function|Undefined callback) |
| Remove multiple elements from the store.
|
Number | size (Function|Undefined callback) |
| Number of entries in this store.
|
Key-value store (linked hash multimap) that lives in shared memory and can be safely accessed from multiple threads.
Can be optionally created over the persistent file on disk. In that case file contents are read on store creation and saved on store destroy (for example, on application shutdown) or on a persist()
call.
Usage example:
var st =
new KVStore(
"path/to/my.json");
st.put("foo", "bar");
st.put("baz": [42, 43]);
st.append("baz", [44, 45, 46];
st.dequeue("baz", 1);
st.remove("foo");
var chan =
new Channel(
"my/channel/name", 1);
chan.send({
kvstoreHandle: st.handle
});
var channel =
Channel.lookup(
"my/channel/name");
var handle = channel.peek().kvstoreHandle;
st.persist();
st.destroy()
Boolean KVStore::append |
( |
String |
key, |
|
|
Array |
values, |
|
|
Function|Undefined |
callback |
|
) |
| |
Extends the array, stored as a value for the specified key, with the specified list of values (appending each value to the end of the array).
If key doesn't exist in the store - it is created with the specified values list.
If key exists in the store, its value must be an Array
.
- Parameters
-
key | String key of the entry to append to, its already inserted value must be a JSON Array |
values | Array list of values to append to the existing list already stored for the specified key |
callback | Function|Undefined callback to receive result or error |
- Returns
Boolean
true
, if the key existed and its value (JSON Array
) was actually appended to; false if key didn't exist and was created with the specified values
list
Number KVStore::dequeue |
( |
String |
key, |
|
|
Integer|Undefined |
count, |
|
|
Function|Undefined |
callback |
|
) |
| |
Removes the specified number of values from the head of the array, stored as a value for the specified key.
If the specified count is larger than a size of an Array
- all elements from Array
are removed.
If key exists in the store, its value must be an Array
.
If key doesn't exist in the store or if Array
is empty - does nothing.
- Parameters
-
key | String key of the entry to to deque from, its already inserted value must be a JSON Array |
count | Integer|Undefined number of elements to dequeue, default value: 1 |
callback | Function|Undefined callback to receive result or error |
- Returns
Number
number of elements dequeued
Object KVStore::KVStore |
( |
String|Undefined|Number |
filePathOrHandle, |
|
|
Function|Undefined |
callback |
|
) |
| |
Create a store instance allocating the native resources for it. If path to file is specified, entries from this file will be be loaded into store and this file will be used to persist the contents of the store.
If empty (or null
) file path specified - store will be memory-only without dist persistence.
If handle value is specified - uses existing store with this handle.
- Parameters
-
filePathOrHandle | String|Undefined|Number this argument represents either a path to the file (String ) where to persist store contents; or a handle (Number ) of the existing KVStore object created in another thread; if argument is null ot not specified persistence is not used |
callback | Function|Undefined callback to receive result or error |
- Returns
Object
KVStore
instance