提供在 MemoryStore 中访问队列的功能。队列是一个数据结构,为任意项目提供临时存储(最大项目尺寸见 内存存储限制)。每个队列项目都有一个数字优先级:MemoryStore首先从队列中检索优先级更高的项目,然后按顺序检索相同优先级的项目。
队列中的项目可以选择在一定时间后过期。过期的项目简单地从队列中消失,如果它们从来没有被添加。
概要
方法
将一件物品添加到队列。
获取队列的大小。
从队列中阅读一个或多个项目。
从队列中删除一个或多个先前阅读的项目。
属性
方法
ReadAsync
参数
返回
代码示例
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
()
参数
默认值:""
返回
()
代码示例
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