This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts.
For thread safety, this property is not safe to read in an unsynchronized thread.
Retrieves the value of a key from a sorted map and lets you update it to a new value via a callback function.
This method accepts a callback function that transforms the old value into the updated value as required. The method retrieves the existing key value and passes it to the transform function which returns the new value for the item, with these exceptions:
- If the key does not exist, the old value passed to the function will be nil.
- If the function returns nil, the update is canceled.
The new value is saved only if the key was not updated (e.g. by a different game server) since the moment it was read. If the value did change, the transform function is invoked again with the most recent item value. This cycle repeats until the value is saved successfully or the transform function returns nil to abort the operation.
For a more in-depth look, take a look at the
articles/Memory Store|Memory Store article.
Key whose value to update.
A function which you need to provide. The function takes the key’s old value as input and returns the new value.
Item expiration time, in seconds, after which the item will be automatically removed from the sorted map. The maximum expiration time is 30 days (2,592,000 seconds).
The return value is the last value returned by the transform function.
Updating a MemoryStore
The code below updates the highest bid for an item in an auction. The use of
MemoryStoreSortedMap/UpdateAsync ensures that the highest bid is not replaced with a lower value even if multiple game servers update the same item simultaneously.