跳转到正文

storage API ​

完整接口目录 · 存储与服务用法 · 工具包下载

模块说明 ​

text
Installation-scoped durable JSON storage using the Host's existing SQLite store.

save acknowledges a committed database transaction, not completion of its game
actions. Only explicit revision rejections may be retried by convenience methods.
Keep a transaction's prepared intent to reconcile a lost reply across restart.

CommitIntent ​

python
@dataclass(frozen=True)
class CommitIntent

SDK 说明:

text
Immutable request; repr omits potentially sensitive values.

字段(包含继承字段):

CommitIntent.method ​

python
method: str

数据类字段;声明于 storage.CommitIntent。

该类型另有以下内部字段,参与数据类声明但不建议直接读写;创建对象时优先使用专题中的工厂方法:

python
_json: str = field(repr=False)

CommitIntent.payload ​

python
def payload(self)

CommitUncertain ​

python
class CommitUncertain(ProtocolError)

CommitUncertain.__init__ ​

python
def __init__(self, intent)

CommitUncertain.intent ​

python
self.intent

公开实例属性,在 __init__ 中设置。

Storage ​

python
class Storage

SDK 说明:

text
A facade over one managed installation. Does not own the peer or a task.

Storage.__init__ ​

python
def __init__(self, peer)

Storage.transaction ​

python
async def transaction(self, *, event=None, commit_id=None, keys=None)

SDK 说明:

text
Read a snapshot. Mutations stay local until explicit save().

keys=None keeps the full snapshot; explicit keys select at most 256
values, with [] reading only the global revision. Selection requires
Host support and never falls back to a full read. CAS remains global.

Storage.get ​

python
async def get(self, key, default=None)

Storage.receipt ​

python
async def receipt(self, commit_id)

SDK 说明:

text
Query a retained commit across generations; never submit it again.

Storage.submit ​

python
async def submit(self, intent, *, timeout=10.0)

SDK 说明:

text
Explicitly submit the unchanged request once; never invent a retry.

Storage.set ​

python
async def set(self, key, value)

Storage.delete ​

python
async def delete(self, key)

Storage.increment ​

python
async def increment(self, key, amount=1, *, default=0)

SDK 说明:

text
Atomically change an integer; return the value actually persisted.

Storage.compare_and_set ​

python
async def compare_and_set(self, key, expected, value)

SDK 说明:

text
Replace an existing JSON value if equal. Missing is distinct from null.

Storage.peer ​

python
self.peer

公开实例属性,在 __init__ 中设置。

Transaction ​

python
class Transaction

SDK 说明:

text
Snapshot plus multi-key mutations, optional event ACK and action intents.

After prepare/save the object is sealed. On explicit conflict create a new
transaction; on uncertainty retain intent, never recompute business logic.

Transaction.__init__ ​

python
def __init__(self, storage, state, *, event=None, commit_id=None, keys=None)

Transaction.session ​

python
@property
def session(self)

SDK 说明:

text
World session of this snapshot, used to prepare matching actions.

Transaction.get ​

python
def get(self, key, default=None)

Transaction.set ​

python
def set(self, key, value)

Transaction.delete ​

python
def delete(self, key)

Transaction.increment ​

python
def increment(self, key, amount=1, *, default=0)

Transaction.action ​

python
def action(self, intent)

Transaction.prepare ​

python
def prepare(self)

Transaction.save ​

python
async def save(self, *, timeout=10.0)

Transaction.storage ​

python
self.storage

公开实例属性,在 __init__ 中设置。

Transaction.revision ​

python
self.revision

公开实例属性,在 __init__ 中设置。

Transaction.commit_id ​

python
self.commit_id

公开实例属性,在 __init__ 中设置。

Transaction.intent ​

python
self.intent

公开实例属性,在 __init__、prepare 中设置。

Neomega · 使用、开发与参考文档