배우기
엔진 클래스
MemoryStoreHashMapPages
만들 수 없음
복제되지 않음

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


요약
상속된 멤버
코드 샘플
메모리 저장소 해시 맵의 항목 나열
local MemoryStoreService = game:GetService("MemoryStoreService")
local testHashMap = MemoryStoreService:GetHashMap("HashMap1")
local EXPIRATION = 600
local NUM_TEST_ITEMS = 32
local function populateHashMap(hashMap: MemoryStoreHashMap, numItems: number): { [string]: any }
print("해시 맵 데이터 설정 중...")
local createdItems = {}
for index = 1, numItems do
local key = tostring(index) -- 해시 맵 키는 문자열이어야 합니다
local value = `{key}_test_value`
local success, result = pcall(hashMap.SetAsync, hashMap, key, value, EXPIRATION)
if success then
createdItems[key] = value
else
warn(`키 {key} 설정 중 오류 발생: {result}`)
end
end
print("해시 맵 데이터 설정 완료.")
return createdItems
end
local function getItemsFromAllPages(pages: MemoryStoreHashMapPages): { [string]: any }
-- 순수하게 로깅 목적으로, 현재 페이지 번호를 추적합니다
local currentPageNumber = 1
local retrievedItems = {}
while not pages.IsFinished do
print(`페이지 {currentPageNumber}의 항목 가져오는 중...`)
local items = pages:GetCurrentPage()
for _, entry in pairs(items) do
print(` {entry.key}: {entry.value}`)
retrievedItems[entry.key] = entry.value
end
-- 읽을 페이지가 더 있으면 페이지를 진행합니다
if not pages.IsFinished then
pages:AdvanceToNextPageAsync()
currentPageNumber += 1
end
end
print("모든 페이지 읽기 완료")
return retrievedItems
end
local function compareAllItems(retrievedItems: { [string]: any }, expectedItems: { [string]: any }): number
print("가져온 항목을 예상 항목과 비교 중...")
local numMatchingItems = 0
for key, expectedValue in pairs(expectedItems) do
if retrievedItems[key] == expectedValue then
numMatchingItems += 1
else
warn(`키 {key}에 대한 가져온 값 불일치: 예상 {expectedValue}, 가져온 {retrievedItems[key]}`)
end
end
print("비교 완료!")
return numMatchingItems
end
-- 해시 맵에 추가된 키는 이 expectedItems 테이블에도 추가됩니다.
-- 나중에, 가져온 해시 맵 항목은 이 예상 항목 테이블과 비교됩니다.
local expectedItems = populateHashMap(testHashMap, NUM_TEST_ITEMS)
-- 페이지 가져오기는 오류가 발생할 수 있습니다. 이 경우, 오류를 발생시키고 프로그램 실행을 중단합니다,
-- 하지만 pcall을 사용하여 다르게 처리할 수 있습니다.
print(`해시 맵 페이지 가져오는 중 ListItemsAsync...`)
local pages = testHashMap:ListItemsAsync(NUM_TEST_ITEMS)
local retrievedItems = getItemsFromAllPages(pages)
local numMatchingItems = compareAllItems(retrievedItems, expectedItems)
-- 항목 설정 또는 가져오는 중 오류가 없었다면, 모든 항목이 일치해야 합니다.
print(`프로그램 완료. {numMatchingItems}/{NUM_TEST_ITEMS} 가져온 항목이 예상 값과 일치합니다.`)
©2026 Roblox Corporation. Roblox 및 Roblox 로고, 'Powering Imagination'은 미국 및 기타 국가 내 당사의 등록 및 미등록 상표입니다.