主题
DataStoreKeyInfo
DataStoreKeyInfo 是 DataStore 读写操作返回的键信息对象,包含创建/更新时间、版本号、scope、key、元数据、用户 ID 和删除状态。
概览
DataStoreKeyInfo 是 DataStore 读写操作返回的键信息对象,包含创建/更新时间、版本号、scope、key、元数据、用户 ID 和删除状态。
不可实例化,由接口返回
函数
GetMetaDatas
签名:GetMetaDatas() -> Table
获取该键的元数据字典。
返回值 Table
读取 KeyInfo 元数据
lua
-- @runtime server
local DataStoreService = game:GetService('DataStoreService')
local Task = game: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 列表。
返回值 Table
读取 KeyInfo 用户 ID
lua
-- @runtime server
local DataStoreService = game:GetService('DataStoreService')
local Task = game: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 | 键值记录的创建时间,标题标注为毫秒时间戳,类型为 Int。它属于 DataStoreKeyInfo,用于描述对应键在数据存储中建立记录的时间信息。(只读) |
UpdatedTime | Int | 0 | 键值记录的更新时间,标题标注为毫秒时间戳,类型为 Int。它由 DataStoreKeyInfo 携带,用于描述该键最近一次写入的时间信息。(只读) |
Version | String | "" | 该记录的版本号,类型为 String。它由 DataStoreKeyInfo 携带,用于标识当前键值信息对应的版本。(只读) |
Scope | String | "" | 该记录所属的前置域(Scope),类型为 String。它由 DataStoreKeyInfo 携带,用于标明键值信息所在的作用域。(只读) |
Key | String | "" | 该记录对应的键名,类型为 String。它由 DataStoreKeyInfo 携带,标识当前键值信息所描述的键。(只读) |
Metas | Table | {} | 用户自定义元数据,类型为 Table。它由 DataStoreKeyInfo 携带,用于存放写入时通过设置选项附加的元数据表。(只读) |
UserIds | Table | [] | 关联的用户 ID 列表,类型为 Table。它由 DataStoreKeyInfo 携带,保存写入时通过设置选项登记的用户标识集合。(只读) |
IsDeleted | Bool | false | 表示当前键值记录是否已被删除,类型为 Bool。它由 DataStoreKeyInfo 携带,用于反映该键的删除状态。(只读) |
