-
tensorstore.KvStore.write(self, key: str | bytes, value: str | bytes | None, *, if_equal: str | bytes | None =
None) Future[KvStore.TimestampedStorageGeneration] Writes or deletes a single key.
Example
>>> store = await ts.KvStore.open({'driver': 'memory'}) >>> await store.write(b'a', b'value') KvStore.TimestampedStorageGeneration(...) >>> await store.read(b'a') KvStore.ReadResult(state='value', value=b'value', stamp=KvStore.TimestampedStorageGeneration(...)) >>> await store.write(b'a', None) KvStore.TimestampedStorageGeneration(...) >>> await store.read(b'a') KvStore.ReadResult(state='missing', value=b'', stamp=KvStore.TimestampedStorageGeneration(...))- Parameters:¶
- key: str | bytes¶
Key to write/delete. This is appended (without any separator) to the existing
path, if any.- value: str | bytes | None¶
Value to store, or
Noneto delete.- if_equal: str | bytes | None =
None¶ If specified, indicates a conditional write operation. The write is performed only if the existing generation associated with
keymatchesif_equal.
- Returns:¶
If no
transactionis specified, returns aFuturethat resolves to the new storage generation forkeyonce the write operation completes and durability is guaranteed (to the extent supported by the driver).If a
transactionis specified, returns aFuturethat resolves to an empty storage generation once the write operation is recorded in the transaction. The write operation is not actually performed until the transaction is committed.
See also