요약
메서드
GetRangeAsync(direction: Enum.SortDirection,count: number,exclusiveLowerBound: Variant,exclusiveUpperBound: Variant):{any} |
RemoveAsync(key: string):() |
UpdateAsync(key: string,transformFunction: function,expiration: number):Tuple |
상속된 멤버
API 참조
메서드
GetRangeAsync
MemoryStoreSortedMap:GetRangeAsync(
direction:Enum.SortDirection, count:number, exclusiveLowerBound:Variant, exclusiveUpperBound:Variant
매개 변수
exclusiveLowerBound:Variant |
exclusiveUpperBound:Variant |
반환
코드 샘플
메모리 저장소 키 가져오기
local MemoryStoreService = game:GetService("MemoryStoreService")
local myMap = MemoryStoreService:GetSortedMap("MySortedMap")
function printAllKeys(map)
-- 초기 하한선은 nil이며, 이는 첫 번째 항목부터 시작함을 의미합니다.
local exclusiveLowerBound = nil
-- 이 루프는 맵의 끝에 도달할 때까지 계속됩니다.
while true do
-- 현재 하한선에서 시작하여 최대 100개의 항목을 가져옵니다.
local items = map:GetRangeAsync(Enum.SortDirection.Ascending, 100, exclusiveLowerBound)
for _, item in ipairs(items) do
print(item.key)
print(item.sortKey)
end
-- 호출에 의해 100개 미만의 항목이 반환되면, 맵의 끝에 도달한 것입니다.
if #items < 100 then
break
end
-- 마지막으로 검색한 키는 다음 반복의 배타적 하한선입니다.
exclusiveLowerBound = {}
exclusiveLowerBound["key"] = items[#items].key
exclusiveLowerBound["sortKey"] = items[#items].sortKey
end
end
printAllKeys(myMap)SetAsync
UpdateAsync
반환
코드 샘플
메모리 스토어 정렬 맵 업데이트
local MemoryStoreService = game:GetService("MemoryStoreService")
local map = MemoryStoreService:GetSortedMap("Leaderboard")
local Players = game:GetService("Players")
function updateLeaderboard(itemKey, killsToAdd, deathsToAdd)
local success, newStats, newScore = pcall(function()
return map:UpdateAsync(itemKey, function(playerStats, playerScore)
playerStats = playerStats or { kills = 0, deaths = 0 }
playerStats.kills += killsToAdd
playerStats.deaths += deathsToAdd
if playerStats then
-- `playerScore`는 맵에서 항목을 정렬하는 데 사용되는 sortKey입니다.
playerScore = playerStats.kills / math.max(playerStats.deaths, 1)
return playerStats, playerScore
end
return nil
end, 30)
end)
end
-- 모든 플레이어에게 처치 1 추가
for i, player in pairs(Players:GetPlayers()) do
updateLeaderboard(player.UserId, 1, 0)
end
-- userId 12345인 플레이어에게 처치 5 및 사망 1 추가
updateLeaderboard(12345, 5, 1)