Module type Tick.KV

module type KV = sig .. end
The type for mutable key-value stores.

KV provides access to typed and named values.



Value codecs


type 'a codec = ('a -> string) * (string -> ('a, Rresult.R.msg) Rresult.result) 
The type for value codecs. An encoder and a decoder.
exception Decode_error of string * Rresult.R.msg
The exception for key value decode errors. If Decode (key, msg) is raised it means that the store's data for key could not be decoded using the client's codec. This exception is not meant to be handled by programs, it indicates a configuration mismatch between the program and its environment.

Keys


type 'a key 
The type for keys with values of type 'a.
val key : string -> 'a codec -> 'a key
key name codec is a key with lookup name name and whose value is codec'd by codec.
val key_name : 'a key -> string
key_name k is k's name.
val key_codec : 'a key -> 'a codec
key_codec k is k's codec.
val mem : 'a key -> bool
mem k is true iff k is bound to a value of type 'a in the key-value store.
val find : 'a key -> 'a option
find k is k's binding in the key-value store (if any).
Raises Decode_error in case of value decode error.
val get : ?absent:'a -> 'a key -> 'a
get k is k's binding the key-value store. If absent is specified this value is returned if k is not bound in the store.
Raises
val set : 'a key -> 'a option -> unit
set k v sets the key value of k to v.

Watching keys


type watcher 
The type for key-value binding change watchers.
val watch : 'a key -> ('a key -> 'a option -> unit) -> watcher
watch k f is a key-value watcher such that whenever key is Tick.KV.set to v, f k v is called.
val unwatch : watcher -> unit
unwatch w stops the watcher w. After that call it's callback is guaranteed not to be called again.