method Kv.putIf
Compare-and-set: writes value only when the version of key is version (0: the key must be absent). Returns whether it did.
Example:
use std.kv { Kv }
use std.core { Utf8 }
fn main() io, db {
let kv = Kv.open("example-putif")!
print("{kv.putIf("k", Utf8.encode("1"), 0)!} {kv.putIf("k", Utf8.encode("2"), 0)!}")
kv.close()
}Output
true false
pub(api) fn putIf(key: str, value: bytes, version: u64) -> bool | KvError dbSince. 1.0.0-beta
Parameters
| Name | Type |
|---|---|
key | str |
value | bytes |
version | u64 |
Returns
bool
Errors
KvError@error
Effects
db
Defined in: std/kv/kv.oxl:507