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()
}Вывод
true false
pub(api) fn putIf(key: str, value: bytes, version: u64) -> bool | KvError dbС версии. 1.0.0-beta
Параметры
| Имя | Тип |
|---|---|
key | str |
value | bytes |
version | u64 |
Возвращает
bool
Ошибки
KvError@error
Эффекты
db
Определено в: std/kv/kv.oxl:507