Class
MemoryStoreSortedMap
NotCreatableNotReplicated
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#
| GetAsync | Retrieves the value and sort key of a key in the sorted map.Yields |
| GetRangeAsync | Retrieves items within a sorted range of keys and sort keys.Yields |
| GetSizeAsync | Gets the size of the sorted map.Yields |
| RemoveAsync | Removes the provided key from the sorted map.Yields |
| SetAsync | Sets the value of a key.Yields |
| UpdateAsync | Retrieves 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.
| Name | Type | Default | Description |
|---|---|---|---|
key | string | Key whose value and sort key to retrieve. |
Returns
Tuple—A tuple of two values:
- Key value, or
nilif there's no item with the specified key. - Sort key, or
nilif there's no sort key associated with the specified key.
- Key value, or
GetRangeAsync(direction: SortDirection, count: int, exclusiveLowerBound: Variant, exclusiveUpperBound: Variant): Array#
Yields
Gets items within a sorted range of keys and sort keys.
| Name | Type | Default | Description |
|---|---|---|---|
direction | SortDirection | Sort direction, ascending or descending. | |
count | int | The number of items to retrieve; the maximum allowed value for this parameter is 200. | |
exclusiveLowerBound | Variant | (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 } . | |
exclusiveUpperBound | Variant | (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.
| Name | Type | Default | Description |
|---|---|---|---|
key | string | Key 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.
| Name | Type | Default | Description |
|---|---|---|---|
key | string | Key whose value to set. | |
value | Variant | Key value to set. | |
expiration | int64 | Item 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). | |
sortKey | Variant | (Optional) Sort key to set for this key. Accepted types are a number (integer or decimal) or a string. |
Returns
boolean—trueif the value of an existing key was overwritten, orfalseif 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.
| Name | Type | Default | Description |
|---|---|---|---|
key | string | Key whose value to update. | |
transformFunction | Function | A 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. | |
expiration | int64 | 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). |
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
Properties (10)
Archivable, archivable, Capabilities, IsInSandbox, Name, Parent, PredictionMode, RobloxLocked, Sandboxed, UniqueId
Methods (39)
AddTag, children, ClearAllChildren, Clone, clone, Destroy, destroy, FindFirstAncestor, FindFirstAncestorOfClass, FindFirstAncestorWhichIsA, FindFirstChild, findFirstChild, FindFirstChildOfClass, FindFirstChildWhichIsA, FindFirstDescendant, GetActor, GetAttribute, GetAttributeChangedSignal, GetAttributes, GetChildren, getChildren, GetDebugId, GetDescendants, GetFullName, GetStyled, GetStyledPropertyChangedSignal, GetTags, HasTag, IsAncestorOf, IsDescendantOf, isDescendantOf, IsPropertyModified, QueryDescendants, Remove, remove, RemoveTag, ResetPropertyToDefault, SetAttribute, WaitForChild