# MemoryStoreSortedMap

Roblox Engine API class from Roblox Studio 0.744.0.7441077 (version-7aaa6838d36c4448).

- Inherits from, nearest first: [Instance](https://rapi.sleaze.dev/classes/Instance.md), [Object](https://rapi.sleaze.dev/classes/Object.md)
- Tags: Not creatable, Not replicated
- Memory category: Instances
- HTML page: https://rapi.sleaze.dev/classes/MemoryStoreSortedMap/
- Roblox documentation: https://create.roblox.com/docs/reference/engine/classes/MemoryStoreSortedMap

Provides access to a sorted map within [`MemoryStoreService`](https://rapi.sleaze.dev/classes/MemoryStoreService.md).

## Methods

### GetAsync

```luau
MemoryStoreSortedMap:GetAsync(key: string): ...any
```

- Tags: Yields, Capabilities: DataStore

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

Parameters:

- `key`: Key whose value and sort key to retrieve.

Returns: 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

```luau
MemoryStoreSortedMap:GetRangeAsync(direction: Enum.SortDirection, count: number, exclusiveLowerBound: any, exclusiveUpperBound: any): { any }
```

- Tags: Yields, Capabilities: DataStore

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

Parameters:

- `direction`: Sort direction, ascending or descending.
- `count`: The number of items to retrieve; the maximum allowed value for this parameter is 200.
- `exclusiveLowerBound`: **(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`: **(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: Item keys, values and sort keys in the requested range.

### GetSizeAsync

```luau
MemoryStoreSortedMap:GetSizeAsync(): number
```

- Tags: Yields, Capabilities: DataStore

Gets the size of the sorted map.

Returns: The number of items currently stored in the sorted map.

### RemoveAsync

```luau
MemoryStoreSortedMap:RemoveAsync(key: string)
```

- Tags: Yields, Capabilities: DataStore

Removes the provided key from the sorted map.

Parameters:

- `key`: Key to remove.

### SetAsync

```luau
MemoryStoreSortedMap:SetAsync(key: string, value: any, expiration: number, sortKey: any): boolean
```

- Tags: Yields, Capabilities: DataStore

Sets the value of a key.

Parameters:

- `key`: Key whose value to set.
- `value`: Key value to set.
- `expiration`: 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`: **(Optional)** Sort key to set for this key. Accepted types are a number (integer or decimal) or a string.

Returns: `true` if the value of an existing key was overwritten, or `false` if a new key was added to the sorted map.

### UpdateAsync

```luau
MemoryStoreSortedMap:UpdateAsync(key: string, transformFunction: (...any) -> ...any, expiration: number): ...any
```

- Tags: Yields, Capabilities: DataStore

Retrieves the value and sort key of a key from a sorted map and updates it with a new value and sort key.

Parameters:

- `key`: Key whose value to update.
- `transformFunction`: 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`: 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: The return value is a tuple of the last value and sort key returned by the transform function.

## Inherited members

- From [Instance](https://rapi.sleaze.dev/classes/Instance.md): `Archivable`, `archivable`, `Attributes`, `AttributesReplicate`, `AttributesSerialize`, `HistoryId`, `Name`, `Parent`, `PredictionMode`, `PropertyStatusStudio`, `RobloxLocked`, `SerializedOverrides`, `SourceAssetId`, `Tags`, `UniqueId`, `numExpectedDirectChildren`, `DataCost`, `Capabilities`, `DefinesCapabilities`, `IsInSandbox`, `Sandboxed`, `AddTag`, `ClearAllChildren`, `Clone`, `Destroy`, `FindFirstAncestor`, `FindFirstAncestorOfClass`, `FindFirstAncestorWhichIsA`, `FindFirstChild`, `FindFirstChildOfClass`, `FindFirstChildWhichIsA`, `FindFirstDescendant`, `GetActor`, `GetAttribute`, `GetAttributeChangedSignal`, `GetAttributes`, `GetChildren`, `GetDebugId`, `GetDescendants`, `GetFullName`, `GetStyled`, `GetStyledPropertyChangedSignal`, `GetTags`, `HasTag`, `IsAncestorOf`, `IsDescendantOf`, `IsPropertyModified`, `QueryDescendants`, `RemoveTag`, `ResetPropertyToDefault`, `SetAttribute`, `WaitForChild`, `Remove`, `children`, `clone`, `destroy`, `findFirstChild`, `getChildren`, `isDescendantOf`, `remove`, `AncestryChanged`, `AttributeChanged`, `ChildAdded`, `ChildRemoved`, `DescendantAdded`, `DescendantRemoving`, `Destroying`, `StyledPropertiesChanged`, `childAdded`
- From [Object](https://rapi.sleaze.dev/classes/Object.md): `ClassName`, `className`, `GetPropertyChangedSignal`, `IsA`, `isA`, `Changed`
