MemoryStoreQueue

显示已弃用

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

无法创建
未复制

提供在 MemoryStore 中访问队列的功能。队列是一个数据结构,为任意项目提供临时存储(最大项目尺寸见 内存存储限制)。每个队列项目都有一个数字优先级:MemoryStore首先从队列中检索优先级更高的项目,然后按顺序检索相同优先级的项目。

队列中的项目可以选择在一定时间后过期。过期的项目简单地从队列中消失,如果它们从来没有被添加。

概要

方法

属性

方法

AddAsync

()
暂停

参数

value: Variant
默认值:""
expiration: number
默认值:""
priority: number
默认值:0

返回

()

GetSizeAsync

暂停

参数

excludeInvisible: boolean
默认值:false

返回

ReadAsync

暂停

参数

count: number
默认值:""
allOrNothing: boolean
默认值:false
waitTimeout: number
默认值:-1

返回

代码示例

Using a MemoryStoreQueue

local MemoryStoreService = game:GetService("MemoryStoreService")
local DataStoreService = game:GetService("DataStoreService")
local queue = MemoryStoreService:GetQueue("PlayerQueue")
local dataStore = DataStoreService:GetDataStore("PlayerStore")
while true do
pcall(function()
-- wait for an item to process
local items, id = queue:ReadAsync(1, false, 30)
-- check if an item was retrieved
if #items > 0 then
-- mark the item as processed
dataStore:UpdateAsync(items[0], function(data)
data = data or {}
data.processed = 1
return data
end)
-- remove the item from the queue
queue:RemoveAsync(id)
end
end)
end

RemoveAsync

()
暂停

参数

id: string
默认值:""

返回

()

代码示例

Using a MemoryStoreQueue

local MemoryStoreService = game:GetService("MemoryStoreService")
local DataStoreService = game:GetService("DataStoreService")
local queue = MemoryStoreService:GetQueue("PlayerQueue")
local dataStore = DataStoreService:GetDataStore("PlayerStore")
while true do
pcall(function()
-- wait for an item to process
local items, id = queue:ReadAsync(1, false, 30)
-- check if an item was retrieved
if #items > 0 then
-- mark the item as processed
dataStore:UpdateAsync(items[0], function(data)
data = data or {}
data.processed = 1
return data
end)
-- remove the item from the queue
queue:RemoveAsync(id)
end
end)
end

活动