Version: 0.8 [BETA] #4
AlternativeLua
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
SuphisDataStoreModule BETA
Before I start, this is not mine but Suphi#3388 module, I got permission to put this up in github. Here is the discord: https://discord.gg/B3zmjPVBce
Features
Suphi's DataStore Module vs ProfileService
ProfileService relies on
os.time()to lock the session. The problem with this is that each serversos.time()may not be 100% in sync. So to combat this problem ProfileService has a session timeout of 30 minutes, but if the servers have aos.time()delta greater then 30 minutes, then the server will be able to bypass the session lock and you will lose data. Another problem is because sessions are locked for 30 minutes, if roblox servers go down and quickly come back up and the server was not able to unlock the sessions. Then players will not be able to enter your game for 30 minutes until the sessions timeout. but will be able to enter other games that dont use ProfileService.So the way Suphi's DataStore Module works is that it uses the
MemoryStoreto save the session lock and because memorystores have a built in expiration time. The memorystore will get automatically removed for all servers at the exact same time and because of this it will be imposible for a server to bypass the session lock. This also allows us to have a very low session timeout of [interval] + 30 seconds. Another benefit of using theMemoryStoreis that instead of usingUpdateAsyncon theDataStore. We only useUpdateAsyncfor theMemoryStore. Which allows us to not waste anyGetandSetrequests for theDataStore. TheMemoryStorehas a request limit of1000 + 100 ⨉ [number of player]per minute while the DataStore only has a request limit of60 + 10 ⨉ [number of player]per minute.ProfileService relays on
RunService.Heartbeatand has a fewwhile true do task.wait()end. on the other hand Suphi's DataStore Module is 100% event driven making it super lightweightProfileService does many DeepTableCopys where it loops your data and copys all values into new tables which can be an exspensive operation for very large tables Suphi's DataStore Module was designed in such a way that it never has to DeepTableCopy
ProfileService forces you to save your data as a table where Suphi's DataStore Module lets you set the datastore value directly where you can save numbers, strings, booleans or tables
Download
Go to releases and download the version(latest stable version prefered), or copy the code in the repo. Alternatively without downloading you can do:
Current version:
0.8 [BETA]Contructors
Returns previously created session else a new session
Returns previously created session else a new session
Returns previously created session else nil
Returns previously created session else nil
Properties
Value of datastore
Metadata associated with the key
An array of UserIds associated with the key
Interval in seconds the datastore will automatically save (set to 0 to disable automatic saving)
Automatically save the data when the session is closed or destroyed
Automatically save the data when the session is closed or destroyed
Unique identifying string
Key used for the datastore
Current state of the session
Number of milliseconds from epoch to when the datastore was created
Number of milliseconds from epoch to when the datastore was updated
Unique identifying string of the current datastore save
Compressed string that is updated before every save if compression is enabled by setting dataStore.Metadata.Compress = {["Level"] = 2, ["Decimals"] = 3, ["Safety"] = true}
Level = 1 (allows mixed tables), Level = 2 (does not allow mixed tables but compresses arrays better), Decimals = amount of decimal places saved, Safety = replace delete character from strings
Events
Fires after state property has changed
Fires just before the data is about to save
Methods
Tries to open the session, optional template parameter will be reconciled onto the value, returns errorType and errorMessage if fails
Loads the datastore value without the need to open the session, optional template parameter will be reconciled onto the value, returns errorType and errorMessage if fails
Force save the current value to the datastore, returns errorType and errorMessage if fails
Closes the session, returns errorType and errorMessage if session is destroyed
Closes and destroys the session, destroyed sessions will be locked
Clones the value property
Fills in missing values from the template into the value property
How much datastore has been used, returns the character count and the second number is a number scaled from 0 to 1 [0 = 0% , 0.5 = 50%, 1 = 100%, 1.5 = 150%]
Simple Example
Load Example
Setup Player Data Example
Setup Player Data Example
Developer Products Example
Setup Player Data Automatic Retry Example
Compression Example
Update
Improved safety
Sessions are more stable
SaveBeforeClose renamed to SaveWhenClosing and is now a boolean
This discussion was created from the release Version: 0.8 [BETA].
Beta Was this translation helpful? Give feedback.
All reactions