MemoryStoreQueue
*Bu içerik, yapay zekâ (beta) kullanılarak çevrildi ve hatalar içerebilir. Sayfayı İngilizce görüntülemek için buraya tıkla.
MemoryStore'ın içinde bir sıra sağlar. Bir sıra, belirli öğeler için geçici depolama sağlayan bir veri yapısıdır (gösterici değerleri depolanır - bakın MemoryStore Limits ). Her sıra öğesi için bir sayısal öncelik vardır: MemoryStore, ilk olarak belirli öğeleri kaydediyor ve ardından aynı önceliği olan öğeleri
Sıraya eklendiğinde öğeleriniz zamanla etkisizleştirilebilir. Zamanlanmış öğeler sıraya giriş yapılmadığında sadece sıraya kaybolur.
Özet
Özellikler
Yöntemler
Sıraya bir öğe ekler.
Sıraya kaydedilmiş bir veya daha fazla öğeyi okur.
Önceki sıraya okunan bir öğeyi veya öğeleri kaldırır.
Özellikler
Yöntemler
AddAsync
Sıraya bir öğe ekler.
Parametreler
Sıraya eklemek için öğenin değeri.
Öğe süresi, saniye olarak, öğe sırayızdan otomatik olarak kaldırılacaktır.
Öğe önceliği. Daha yüksek önceliğe sahip olan öğeler sırayla daha düşük önceliğe sahip olan öğelerden alınır.
Dönüşler
ReadAsync
Tek bir özellik olarak kuyruktan bir veya daha fazla öğeyi okur.
Bu yöntem, döndürilen öğeleri sırayı kaldırmak için otomatik olarak silmez, ancak görünmezliğin süresi boyunca diğer ReadAsync çağrıları için görünmez hale getirir. Öğeleri görünmezliğin süresi dolmadan önce MemoryStoreQueue:RemoveAsync() iletkenliği
Parametreler
okuöğelerin sayısı. Bu parametrenin maksimum değeri 100'dir.
Eğer sıra count tane ile daha azsa davranışını kontrol eder: eğer yanlış yapılandırılmışsa yanlış yanıtı içerir; eğer doğru yanılandırılmışsa hiç yanıt vermez.Varsayılan değer yanlıştır.
Gereken öğe sayısı hemen kullanılmazsa, yöntemin bekleyeceği süre, saniye olarak, işlenir. Bu süre iki saniye içinde her iki saniyede bir tekrar deneyinir. Bu parametre, beklemek için sıfıra ayarlanabilir veya -1 olarak belirlenir. Bu parametre sağlanmazsa veya belirlenmezse, yöntem kalıcı olarak bekleyecektir.
Dönüşler
İki elemanın bir tuşu. İlk eleman, sıraya okunan bir öğe arayüzüdür. İkinci eleman, bu öğeleri sürekli olarak kaybı etmek için MemoryStoreQueue:RemoveAsync() ile kalıcı olarak bu öğeleri kaydırmanız gereken bir yol göstergesidir.
Kod Örnekleri
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:
- If MemoryStoreQueue:ReadAsync() fails, no items are retrieved from the queue. An item will be picked up for processing during the next iteration of the loop.
- If MemoryStoreQueue:ReadAsync() succeeds but DataStoreService:UpdateAsync() fails, the item stays invisible until the queue's invisibility timeout expires, causing the item becoming visible again to be returned in a future loop iteration.
- Similarly, if MemoryStoreQueue:RemoveAsync() fails, the item will become visible again in the future and will be processed again.
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.
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
Önce sıraya okunan bir öğeyi veya öğeleri kaldırır. Bu yöntem MemoryStoreQueue:ReadAsync() ile okunan öğeleri tanımlar. Çağrı, görünmezluk süresi dolduktan sonra yapılır. Çağrı, görünmezluk süresi dolduktan sonra yapılır.
Parametreler
Silinecek öğeleri belirtir. MemoryStoreQueue:ReadAsync() tarafından döndürülenen değer kullanın.
Dönüşler
Kod Örnekleri
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:
- If MemoryStoreQueue:ReadAsync() fails, no items are retrieved from the queue. An item will be picked up for processing during the next iteration of the loop.
- If MemoryStoreQueue:ReadAsync() succeeds but DataStoreService:UpdateAsync() fails, the item stays invisible until the queue's invisibility timeout expires, causing the item becoming visible again to be returned in a future loop iteration.
- Similarly, if MemoryStoreQueue:RemoveAsync() fails, the item will become visible again in the future and will be processed again.
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.
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