Roblox UtilitiesDevlHub Roblox Documentation

Class

MemoryStoreSortedMap

NotCreatableNotReplicated
Inherits
Instance › Object
Memory category
Instances

Provides access to a sorted map within MemoryStoreService.

Provides access to a sorted map within MemoryStoreService. A sorted map is a collection of items where string keys are associated with arbitrary values (up to the maximum allowed size -- see Memory Stores). Each item can also have an optional sort key, which can be a number or a string. In the ordering of items, the sort key, if provided, takes precedence over the key. Items with numeric sort keys are sorted before items with string sort keys, which are sorted before items with no sort key. Items with the same sort key and items with no sort key are arranged in alphabetical order by key.

Methods 6#

GetAsyncRetrieves the value and sort key of a key in the sorted map.Yields
GetRangeAsyncRetrieves items within a sorted range of keys and sort keys.Yields
GetSizeAsyncGets the size of the sorted map.Yields
RemoveAsyncRemoves the provided key from the sorted map.Yields
SetAsyncSets the value of a key.Yields
UpdateAsyncRetrieves the value and sort key of a key from a sorted map and updates it with a new value and sort key.Yields

GetAsync(key: string): Tuple#

Yields

Retrieves the value and sort key of a key in the sorted map.

NameTypeDefaultDescription
keystringKey whose value and sort key to retrieve.
Returns
  • Tuple —

    A tuple of two values:

    • Key value, or nil if there's no item with the specified key.
    • Sort key, or nil if there's no sort key associated with the specified key.

GetRangeAsync(direction: SortDirection, count: int, exclusiveLowerBound: Variant, exclusiveUpperBound: Variant): Array#

Yields

Gets items within a sorted range of keys and sort keys.

NameTypeDefaultDescription
directionSortDirectionSort direction, ascending or descending.
countintThe number of items to retrieve; the maximum allowed value for this parameter is 200.
exclusiveLowerBoundVariant(Optional) Lower bound, exclusive, for the returned keys. This is provided as a table where one or both of key and sort key can be specified: { key: string, sortKey: Variant } .
exclusiveUpperBoundVariant(Optional) Upper bound, exclusive, for the returned keys. This is provided as a table where one or both of key and sort key can be specified: { key: string, sortKey: Variant } .
Returns
  • Array — Item keys, values and sort keys in the requested range.

GetSizeAsync(): int#

Yields

Gets the size of the sorted map.

Returns
  • int — The number of items currently stored in the sorted map.

RemoveAsync(key: string): ()#

Yields

Removes the provided key from the sorted map.

NameTypeDefaultDescription
keystringKey to remove.
Returns
  • ()

SetAsync(key: string, value: Variant, expiration: int64, sortKey: Variant): boolean#

Yields

Sets the value and sort key of the key overwriting any existing key value and sort key.

NameTypeDefaultDescription
keystringKey whose value to set.
valueVariantKey value to set.
expirationint64Item expiration, in seconds. The item is automatically removed from the sorted map once the expiration duration is reached. The maximum expiration time is 45 days (3,888,000 seconds).
sortKeyVariant(Optional) Sort key to set for this key. Accepted types are a number (integer or decimal) or a string.
Returns
  • boolean — true if the value of an existing key was overwritten, or false if a new key was added to the sorted map.

UpdateAsync(key: string, transformFunction: Function, expiration: int64): Tuple#

Yields

Retrieves the value and sort key of a key from a sorted map and lets you update it to a new value and sort key via a callback function.

This method accepts a callback function that transforms the old value and old sort key into the updated value and updated sort key as required. The method retrieves the existing key value and sort key and passes it to the transform function which returns the new value and sort key for the item, with these exceptions:

  • If the key does not exist, the old value and old sort key passed to the function will be nil.
  • If the function returns nil, the update is canceled.

The new value and new sort key 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 or sort key did change, the transform function is invoked again with the most recent item value and sort key. This cycle repeats until the value and sort key are saved successfully or the transform function returns nil to abort the operation.

NameTypeDefaultDescription
keystringKey whose value to update.
transformFunctionFunctionA function which you need to provide. The function takes the key's old value and old sort key as input and returns the new value and new sort key.
expirationint64Item 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).
Returns
  • Tuple — The return value is a tuple of the last value and sort key returned by the transform function.

Inherited members#

Inherited from Instance 58
Inherited from Object 6
Properties (2)

ClassName, className

Events (1)

Changed