LiteyukiBot/docs/en/dev/api/liteyuki/comm/storage.md

93 lines
1.3 KiB
Markdown
Raw Normal View History

2024-08-19 01:43:46 +00:00
---
title: liteyuki.comm.storage
order: 1
icon: laptop-code
category: API
---
### ***def*** `on_get(data: tuple[str, dict[str, Any]]) -> None`
### ***def*** `on_set(data: tuple[str, dict[str, Any]]) -> None`
### ***def*** `on_delete(data: tuple[str, dict[str, Any]]) -> None`
### ***def*** `on_get_all(data: tuple[str, dict[str, Any]]) -> None`
### ***class*** `KeyValueStore`
###   ***def*** `__init__(self) -> None`
 
###   ***def*** `set(self, key: str, value: Any) -> None`
2024-08-19 01:55:47 +00:00
 设置键值对
2024-08-19 01:43:46 +00:00
Args:
2024-08-19 01:55:47 +00:00
2024-08-19 01:43:46 +00:00
key: 键
2024-08-19 01:55:47 +00:00
2024-08-19 01:43:46 +00:00
value: 值
###   ***def*** `get(self, key: str, default: Optional[Any]) -> Optional[Any]`
2024-08-19 01:55:47 +00:00
 获取键值对
2024-08-19 01:43:46 +00:00
Args:
2024-08-19 01:55:47 +00:00
2024-08-19 01:43:46 +00:00
key: 键
2024-08-19 01:55:47 +00:00
2024-08-19 01:43:46 +00:00
default: 默认值
2024-08-19 01:55:47 +00:00
2024-08-19 01:43:46 +00:00
Returns:
2024-08-19 01:55:47 +00:00
2024-08-19 01:43:46 +00:00
Any: 值
###   ***def*** `delete(self, key: str, ignore_key_error: bool) -> None`
2024-08-19 01:55:47 +00:00
 删除键值对
2024-08-19 01:43:46 +00:00
Args:
2024-08-19 01:55:47 +00:00
2024-08-19 01:43:46 +00:00
key: 键
2024-08-19 01:55:47 +00:00
2024-08-19 01:43:46 +00:00
ignore_key_error: 是否忽略键不存在的错误
Returns:
###   ***def*** `get_all(self) -> dict[str, Any]`
2024-08-19 01:43:46 +00:00
2024-08-19 01:55:47 +00:00
 获取所有键值对
2024-08-19 01:43:46 +00:00
2024-08-19 01:55:47 +00:00
Returns:
2024-08-19 01:43:46 +00:00
2024-08-19 01:55:47 +00:00
dict[str, Any]: 键值对
### ***class*** `GlobalKeyValueStore`
2024-08-19 01:43:46 +00:00
2024-08-19 01:55:47 +00:00
###   ***@classmethod***
###   ***def*** `get_instance(cls: Any) -> None`
2024-08-19 01:43:46 +00:00
2024-08-19 01:55:47 +00:00
 
2024-08-19 01:43:46 +00:00
2024-08-19 01:55:47 +00:00
###   ***attr*** `_instance: None`
2024-08-19 01:43:46 +00:00
2024-08-19 01:55:47 +00:00
###   ***attr*** `_lock: threading.Lock()`
2024-08-19 01:43:46 +00:00