Data Store
*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.
Tóm tắt
Phương Pháp
GetVersionAsync(key: string,version: string):Tuple |
GetVersionAtTimeAsync(key: string,timestamp: number):Tuple |
ListKeysAsync(prefix: string,pageSize: number,cursor: string,excludeDeleted: boolean):DataStoreKeyPages |
ListVersionsAsync(key: string,sortDirection: Enum.SortDirection,minDate: number,maxDate: number,pageSize: number):DataStoreVersionPages |
RemoveVersionAsync(key: string,version: string):() |
Thành viên kế thừa
7 thành viên kế thừa từ GlobalDataStore
58 thành viên kế thừa từ Instance
6 thành viên kế thừa từ Object
Tài Liệu Tham Khảo API
Phương Pháp
Get Version Async
Get Version At Time Async
Lợi Nhuận
Mẫu mã
Lấy phiên bản DataStore theo thời gian
local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetDataStore("DataStore")
local key = "key-123"
function setData(data)
local success, result = pcall(function()
dataStore:SetAsync(key, data)
end)
if not success then
warn(result)
end
end
function getVersionAtTime(timestamp)
local success, result, keyInfo = pcall(function()
return dataStore:GetVersionAtTimeAsync(key, timestamp.UnixTimestampMillis)
end)
if success then
if result == nil then
print("Không tìm thấy phiên bản nào tại thời điểm này")
else
print(result, keyInfo.Version)
end
else
warn(result)
end
end
-- Đã chạy trước đó vào 2024/12/02 6:00 UTC
setData("phiên bản 1")
-- Đã chạy trước đó vào 2024/12/02 9:00 UTC
setData("phiên bản 2")
-- In ra "Không tìm thấy phiên bản nào tại thời điểm này"
local time1 = DateTime.fromUniversalTime(2024, 12, 02, 05, 00)
getVersionAtTime(time1)
-- In ra "phiên bản 1 <version>"
local time2 = DateTime.fromUniversalTime(2024, 12, 02, 07, 00)
getVersionAtTime(time2)
-- In ra "phiên bản 2 <version>"
local time3 = DateTime.fromUniversalTime(2024, 12, 02, 10, 00)
getVersionAtTime(time3)List Keys Async
Data Store: List Keys Async(
Lợi Nhuận
List Versions Async
Data Store: List Versions Async(
Tham Số
| Giá Trị Mặc Định: Ascending |
| Giá Trị Mặc Định: 0 |
| Giá Trị Mặc Định: 0 |
| Giá Trị Mặc Định: 0 |
Lợi Nhuận
Mẫu mã
Lấy Phiên Bản DataStore Với Bộ Lọc Ngày
local DataStoreService = game:GetService("DataStoreService")
local experienceStore = DataStoreService:GetDataStore("PlayerExperience")
local time = DateTime.fromUniversalTime(2020, 10, 09, 01, 42)
local listSuccess, pages = pcall(function()
return experienceStore:ListVersionsAsync("User_1234", nil, time.UnixTimestampMillis)
end)
if listSuccess then
local items = pages:GetCurrentPage()
for key, info in pairs(items) do
print("Khóa:", key, "; Phiên bản:", info.Version, "; Được tạo:", info.CreatedTime, "; Đã xóa:", info.IsDeleted)
end
endRemove Version Async