store.put()
写入一个键。传入 expectedVersion 时,只有当前版本匹配才成功。
Syntax
const result = await host.store.put(key, value, expectedVersion?);
Parameters
| 参数 | 类型 | 说明 |
|---|---|---|
key |
string |
有界、规范化的应用键 |
value |
ByteSource |
无类型字节值 |
expectedVersion |
u64 |
可选并发前置条件 |
Return value
{ version: u64 }:成功后的新版本。
Examples
const old = await host.store.get('counter');
const next = encode((old ? decode(old.value) : 0) + 1);
await host.store.put('counter', next, old?.version);
Errors
conflict、invalid-key、quota-exceeded、limit-exceeded。冲突不得覆盖现值。