Roblox UtilitiesDevlHub Roblox Documentation

Class

MemoryStoreHashMap

NotCreatableNotReplicated
Inherits
Instance › Object
Memory category
Instances

Provides access to a hash map within MemoryStoreService.

Provides access to a hash map within MemoryStoreService. A hash map is a collection of items where string keys are associated with arbitrary values (up to the maximum allowed size -- see Memory Stores). The keys have no ordering guarantees.

Methods 5#

GetAsyncRetrieves the value of a key in the hash map.Yields
ListItemsAsyncReturns a MemoryStoreHashMapPages object for enumerating through items in the hash map.Yields
RemoveAsyncRemoves an item from the hash map.Yields
SetAsyncSets the value of a key in the hash map.Yields
UpdateAsyncRetrieves the value of a key from a hash map and lets you update it to a new value.Yields

GetAsync(key: string): Variant#

Yields

Retrieves the value of a key in the hash map.

NameTypeDefaultDescription
keystringThe key whose value you want to retrieve.
Returns
  • Variant — The value, or nil if the key doesn't exist.

ListItemsAsync(count: int): MemoryStoreHashMapPages#

Yields

Returns a MemoryStoreHashMapPages object for enumerating through items in the hash map. The valid range is 1 to 200 inclusive.

NameTypeDefaultDescription
countintMaximum possible number of items that can be returned.
Returns

RemoveAsync(key: string): ()#

Yields

Removes an item from the hash map.

NameTypeDefaultDescription
keystringThe key to remove.
Returns
  • ()

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

Yields

Sets the value of a key in the hash map, overwriting any existing value.

NameTypeDefaultDescription
keystringThe key whose value to set.
valueVariantThe value to set.
expirationint64Item expiration in seconds, after which the item is automatically removed from the hash map. The maximum expiration time is 45 days (3,888,000 seconds).
Returns
  • boolean — true if the key already had a value that was overwritten, or false if the key was newly created.

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

Yields

Retrieves the value of a key from a hash map and lets you update it to a new value.

This method accepts a callback function that retrieves the existing key value and passes it to a 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 is nil.
  • If the function returns nil, the update is canceled.

The new value is saved only if the key was not updated (for example, by a different game server) since the moment it was read. If the value changed in that time, the transform function is called 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.

NameTypeDefaultDescription
keystringThe key whose value you want to update.
transformFunctionFunctionThe transform function, which you provide. This function takes the old value as an input and returns the new value.
expirationint64Item expiration in seconds, after which the item is automatically removed from the hash map. The maximum expiration time is 45 days (3,888,000 seconds).
Returns
  • Variant — The last value returned by the transform function.

Inherited members#

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

ClassName, className

Events (1)

Changed