主题
DataStoreKeyInfo
DataStore 键信息对象,由 GetAsync / SetAsync 等方法返回。
概览
DataStoreKeyInfo 是 DataStore 读写操作返回的键信息对象,包含创建/更新时间、版本号、scope、key、元数据、用户 ID 和删除状态。
不可实例化,由接口返回
函数
GetMetaDatas
签名:GetMetaDatas() -> Table
返回与此数据键关联的用户自定义元数据字典。元数据是写入数据时通过相关写入选项一并保存的额外信息,字典以字符串为键,值为任意类型。
返回值 Table — 元数据表(键为字符串,值为任意类型)
读取 KeyInfo 元数据
lua
-- @runtime client
local DataStoreService = editor:GetService('DataStoreService')
local Task = editor:GetService('Task')
local dataStore = DataStoreService:GetDataStore('PlayerData', 'global')
Task:Spawn(function()
local options = DataStoreGetOptions.New()
options.WithKeyInfo = true
local _, keyInfo = dataStore:GetAsync('player_001', options)
local metas = keyInfo and keyInfo:GetMetaDatas() or {}
print(metas.source)
end)GetUserIds
签名:GetUserIds() -> Table
返回与此数据键关联的用户 ID 列表。列表中的每个元素对应一个用户标识,用于记录该键与哪些用户 ID 相关联。
返回值 Table — 用户 ID 列表
读取 KeyInfo 用户 ID
lua
-- @runtime client
local DataStoreService = editor:GetService('DataStoreService')
local Task = editor:GetService('Task')
local dataStore = DataStoreService:GetDataStore('PlayerData', 'global')
Task:Spawn(function()
local options = DataStoreGetOptions.New()
options.WithKeyInfo = true
local _, keyInfo = dataStore:GetAsync('player_001', options)
for _, userId in ipairs((keyInfo and keyInfo:GetUserIds()) or {}) do
print(userId)
end
end)属性
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
CreatedTime | Int | 0 | 记录该键信息的创建时间,以毫秒为单位的整数时间戳形式表示。(只读) |
UpdatedTime | Int | 0 | 记录该键信息的最近更新时间,以毫秒为单位的整数时间戳形式表示。(只读) |
Version | String | "" | 该键信息对应的版本号,用于标识当前键信息所对应的数据版本。(只读) |
Scope | String | "" | 该键所属的前置域(Scope)名称,用于标明键所在的命名空间。(只读) |
Key | String | "" | 存储该键信息对应的数据键名称,用于表明当前 DataStoreKeyInfo 描述的是哪一个键。(只读) |
Metas | Table | {} | 与此键关联的用户自定义元数据表,保存写入该键数据时附带的自定义元数据内容。(只读) |
UserIds | Table | [] | 与此键关联的用户 ID 列表,以数组形式保存与当前键相关的用户标识。(只读) |
IsDeleted | Bool | false | 标识与该键信息对应的数据记录是否处于已删除状态。(只读) |
