MemoryStoreQueue

사용되지 않는 항목 표시

*이 콘텐츠는 AI(베타)를 사용해 번역되었으며, 오류가 있을 수 있습니다. 이 페이지를 영어로 보려면 여기를 클릭하세요.

만들 수 없음
복제되지 않음

MemoryStore 내에서 큐에 액세스를 제공합니다.큐는 임의의 항목에 대한 임시 저장소를 제공하는 데이터 구조(최대 항목 크기 참조: MemoryStore 제한)입니다.각 대기열 항목에는 숫자 우선 순위가 있습니다: MemoryStore는 우선 순위가 더 높은 항목을 먼저 대기열에서 검색하고, 동일한 우선 순위의 항목을 순서대로 검색합니다.

큐에 있는 항목은 특정 시간 후에 만료되도록 선택적으로 설정할 수 있습니다.만료된 항목은 단순히 큐에서 삭제되어 추가되지 않은 것처럼 보입니다.

요약

메서드

속성

메서드

AddAsync

()
생성

큐에 아이템을 추가합니다.

매개 변수

value: Variant

큐에 추가할 아이템의 값.

기본값: ""
expiration: number

아이템 만료 시간, 초 단위, 이후 아이템이 큐에서 자동으로 제거됩니다.

기본값: ""
priority: number

아이템 우선 순위. 우선 순위가 높은 아이템은 우선 순위가 낮은 아이템보다 먼저 큐에서 검색됩니다.

기본값: 0

반환

()

ReadAsync

생성

큐에서 하나 이상의 항목을 단일 원자 작업으로 읽습니다.

이 메서드는 반환된 항목을 자동으로 큐에서 삭제하지 않지만 투명화 시간 제한 기간 동안 다른 ReadAsync 호출에서 보이지 않게 만듭니다.가시성 제한 시간이 만료되기 전에 목록에서 명시적으로 제거해야 합니다.The items must be explicitly removed from the queue with MemoryStoreQueue:RemoveAsync() before the invisibility timeout expires.투명화 제한 시간은 다른 값이 제공되지 않은 경우 30초로 기본값이 설정되지만 MemoryStoreService:GetQueue()에 다른 값이 제공된 경우 기본값은 30초로 변경됩니다.

매개 변수

count: number

읽음아이템 수. 이 매개변수의 최대 허용 값은 100입니다.

기본값: ""
allOrNothing: boolean

큐에 아이템이 개 미만인 경우 메서드의 동작을 제어합니다: false로 설정하면 사용 가능한 모든 아이템이 반환됩니다; true로 설정하면 아이템이 반환되지 않습니다.기본값은 false입니다.

기본값: false
waitTimeout: number

큐에 필요한 항목 수가 즉시 사용할 수 없는 경우 메서드가 대기할 시간(초)입니다. The duration, in seconds, for which the method will wait if the required number of items is not immediately available in the queue.이 기간 동안 매 2초마다 읽기가 시도됩니다.이 매개변수는 대기 없음을 나타내기 위해 0으로 설정할 수 있습니다.이 매개 변수가 제공되지 않거나 -1로 설정되지 않으면 메서드가 무기한 대기합니다.

기본값: -1

반환

2개의 요소로 된 튜플.첫 번째 요소는 큐에서 읽은 아이템 값 배열입니다.두 번째 요소는 이러한 항목을 영구적으로 제거하기 위해 MemoryStoreQueue:RemoveAsync()에 전달해야 하는 문자열 식별자입니다.

코드 샘플

The following code sample demonstrates using MemoryStoreQueue:ReadAsync() and MemoryStoreQueue:RemoveAsync() to reliably read, process, and remove items from a queue. Though this process can be as complicated as necessary, this example simply sets a flag in the corresponding data store item, which guarantees that every item will eventually be processed even if some of the calls encounter errors or the server crashes:

Depending on where the failure happens, it's possible that an item will be processed more than once. You should account for that like the following code sample, in which the end result is the same even if DataStoreService:UpdateAsync() is invoked multiple times.

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

()
생성

이전에 큐에서 읽은 항목이나 항목을 제거합니다.이 메서드는 MemoryStoreQueue:ReadAsync()에서 반환된 식별자를 사용하여 제거할 항목을 식별합니다.투명화 제한 시간이 만료된 후에 호출하면 호출 효과가 없습니다.

매개 변수

id: string

삭제할 항목을 식별합니다. MemoryStoreQueue:ReadAsync() 에서 반환된 값을 사용합니다.

기본값: ""

반환

()

코드 샘플

The following code sample demonstrates using MemoryStoreQueue:ReadAsync() and MemoryStoreQueue:RemoveAsync() to reliably read, process, and remove items from a queue. Though this process can be as complicated as necessary, this example simply sets a flag in the corresponding data store item, which guarantees that every item will eventually be processed even if some of the calls encounter errors or the server crashes:

Depending on where the failure happens, it's possible that an item will be processed more than once. You should account for that like the following code sample, in which the end result is the same even if DataStoreService:UpdateAsync() is invoked multiple times.

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

이벤트