主题
DataStoreKeyBriefInfoPages
概览
| 字段 | 值 |
|---|---|
| Kind | Data · 数据 Data |
| Realm | server |
继承关系
- Pages(1 属性 / 2 函数)
- [DataStoreKeyBriefInfoPages]
继承成员
1 个来源 / 1 属性 / 2 函数
- 来自 Pages(1 属性 / 2 函数)
DataStoreKeyBriefInfoPages 是 DataStore:ListKeysAsync 返回的分页迭代器,GetCurrentPage() 返回 DataStoreKeyBriefInfo 数组。
适用场景
用于按前缀分页列出某个 DataStore 内的 key,常见于管理存档、清理废弃 key 或做数据迁移检查。
使用要点
该类型不可直接构造,应先通过 DataStoreService:GetDataStore 获取 DataStore,再调用 ListKeysAsync 得到 pages。ListKeysAsync 是异步方法,需在协程环境中调用。
代码示例
列出 DataStore key 分页
lua
-- @runtime server
local DataStoreService = game:GetService('DataStoreService')
local Task = game:GetService('Task')
local dataStore = DataStoreService:GetDataStore('PlayerData', 'global')
Task:Spawn(function()
local options = DataStoreListKeyOptions.New()
options.ExcludeDeleted = true
local pages = dataStore:ListKeysAsync('player_', 10, '', options)
for _, keyInfo in ipairs(pages:GetCurrentPage()) do
print(keyInfo.Scope, keyInfo.Key, keyInfo.IsDeleted)
end
end)