返回值
{
id: "…", // the session id
storageId: "…" // the storage this session is bound to, or null
}{
"id": "…", # the session id
"storageId": "…", # the storage this session is bound to, or None
}idstring什麽 撤销( ) 取用。
storageIdstring|null服务器将这个进程存储为哪个 。 对于机器来说, 机器在重新启动时会保持一个身份 。
如何回答
| 缓存状态 | 发生什么 |
|---|---|
| 选择了会话代号 | 立即返回——没有网络 |
| 标记已缓存, 但无代号 | 列出活动会话,并匹配同一存储的会话 |
| 列名失败 | 无效——失败被吞吞,没有被抛 |
| 什么都没有缓存 | 空无一物,无所交换 以找出 |
第二行是为什么这种方法比它看从旧缓存中恢复的客户端慢。第一行是正常情况。
它不会创造一会,它不会抛弃,
冷酷客户的回答是无效的。 任何普通的电话先打—— 获得用户( GetUser) 是最便宜的 — 交换会在那里发生。 因为它吞噬了自己的失败, 一个无名氏从未告诉你网络已经倒闭; 它告诉你方法不能命名会话。
const fresh = new IaGenify({ apiKey });
await fresh.session(); // null — nothing has been exchanged
await fresh.getUser(); // this is what exchanges
await fresh.session(); // { id, storageId }fresh = IaGenify(api_key=api_key)
fresh.session() # None — nothing has been exchanged
fresh.get_user() # this is what exchanges
fresh.session() # {"id", "storageId"}用途
- 显示一个进程以什么方式运行, 在一个仪表板上, 或者在启动时用一个日志行 。
- 将ID传给 撤销( )包括结束这届会议 从别的地方。
- 阅读
storageId以确认服务器是否承认此机器为您预期的机器, 而不是注册第二个机器 。
启动一线
const [user, session] = await Promise.all([api.getUser(), api.session()]);
console.log(
`iagenify · ${user?.email} · session ${session?.id ?? "none"} · storage ${session?.storageId ?? "none"}`,
);user, session = api.get_user(), api.session()
print(
f"iagenify · {(user or {}).get('email')} · "
f"session {(session or {}).get('id', 'none')} · storage {(session or {}).get('storageId') or 'none'}"
)确认一台机器, 数量不多
机器发送 storageId 当部署在每次重新启动时失去会话缓存时,每个靴子都登记一个新的——它显示成一堆几乎相同的储存。
const before = (await api.session())?.storageId;
// … restart the process, with the same sessionPath …
const after = (await api.session())?.storageId;
// Same value: one machine. A different one: the session cache did not survive.before = (api.session() or {}).get("storageId")
# … restart the process, with the same session_path …
after = (api.session() or {}).get("storageId")
# Same value: one machine. A different one: the session cache did not survive.集装箱,每个启动一次没有持久性会话路径登记册
挂载会话路径, 或者通过您控制的存储。 否则每次重新启动都是服务器的新机器, 以及您所依赖的您下面的更改的身份 。
届会不连续举行的
在没有耐久储存的运行过程中,会议会活在记忆中,只要孤立状态能够——所以 session() 答案是这个孤立, 答案是没有别的。 这是商店的属性, 不是这个方法, 而是你提供的商店 改变了它 。
结束
const current = await api.session();
await api.auth.logout(); // this one
await api.auth.revokeSession(id); // another, by idcurrent = api.session()
api.auth.logout() # this one
api.auth.revoke_session(session_id) # another, by id注意不对称性: 此方法为您提供 您的 id. 另一台机器的ID不是 SDK 列表中 - - 当你想要机器关闭时, 撤销它持有的密钥 。