Collapse Sidebar


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.


Name Type Default Description


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 45 days (3,888,000 seconds).


Return Type Summary

The return value is the last value returned by the transform function.

Code Samples

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.