data Kv
Handle of an open store.
Example:
use std.kv { Kv }
fn main() io, db {
let kv = Kv.open("docs-kv")!
kv.put("greeting", b"hello")!
print("{kv.get("greeting")!.len()}")
kv.close()
}Output
5
@derive(Copy)
pub(api) data KvThread safety. a handle may be shared by tasks; single operations are linearizable.
Since. 1.0.0-beta
Fields
pub(api) h: i64 | Handle of the store in the runtime. |
Methods
reading | (mode: Consistency, maxStale: Duration) -> KvA handle on the same store whose get and scan use mode (writes and transactions are not affected |
open | (name: str) -> Kv | KvError dbOpens (creates) the store name; "name?shards=4" (or $OXL_KV_SHARDS) sets the number of shards (default 1). |
close | () dbCloses the handle; later calls on it fail. |
get | (key: str) -> bytes? | KvError dbThe value of key, or none. |
getEntry | (key: str) -> KvEntry? | KvError dbThe value and version of key, or none. |
version | (key: str) -> u64 | KvError dbThe version of key (0 = absent). |
put | (key: str, value: bytes) -> () | KvError dbStores value under key. |
delete | (key: str) -> () | KvError dbRemoves key; a missing key is not an error. |
putIf | (key: str, value: bytes, version: u64) -> bool | KvError dbCompare-and-set |
scan | (prefix: str, limit: i64) -> List<KvEntry> | KvError dbEntries whose key starts with prefix, ascending; at most limit (0 = all). |
scanAfter | (prefix: str, after: str, limit: i64) -> List<KvEntry> | KvError dbLike scan, continuing strictly after the key after (paging). |
txn | (body: fn(KvTx) -> R F) -> R | KvError db, FRuns body in an optimistic transaction |
watch | (prefix: str) -> stream<KvEvent, KvError> dbThe changes to keys with this prefix from now on, in commit order per shard. |
Defined in: std/kv/kv.oxl:205