Skip to main content

MemoryShard

A memory shard is a way to split up the leaderboard into multiple shards, each shard is a MemoryStoreSortedMap

Types​

MemoryShard​

type MemoryShard = () → MemoryShard

MemoryShardArguments​

interface MemoryShardArguments {
_boardKey: string
_fallbackExpiry: number
_isRollingExpiry: boolean
_shardCount: number
_logger: Logger.Logger?
_maxRecords: number
}

Object​

interface Object {
__index: Object
_getShardKey: (
self: MemoryShard,
userId: number
) → (number)
_getAsync: (
self: MemoryShard,
key: string
) → any
_setAsync: (
self: MemoryShard,
key: string,
value: any,
expiry: number,
sortKey: number
) → boolean
_updateAsync: (
self: MemoryShard,
key: string,
transformer: (any) → (any),
expiry: number
) → boolean
_cleanupShards: (
self: MemoryShard,
maxEntriesPerShard: number?
) → Promise.TypedPromise<boolean>
_removeKeyFromShard: (
self: MemoryShard,
shardIndex: number,
key: string
) → Promise.TypedPromise<boolean>
_getShardSize: (
self: MemoryShard,
shardIndex: number
) → Promise.TypedPromise<number>
CleanupNow: (
self: MemoryShard,
maxEntriesPerShard: number?
) → Promise.TypedPromise<boolean>
Set: (
self: MemoryShard,
userId: number,
value: number | (number) → (number)
) → Promise.TypedPromise<boolean>
Get: (
self: MemoryShard,
amount: number,
sortDirection: string
) → Promise.TypedPromise<{TopData}>
Destroy: (self: MemoryShard) → ()
new: (
leaderboardType: LeaderboardType,
boardKey: string,
shardCount: number,
maxRecords: number?,
rollingExpiry: number?,
debugMode: boolean?
) → MemoryShard
}

Functions​

new​

MemoryShard.new(
leaderboardType: LeaderboardType,
boardKey: string,
shardCount: number,
maxRecords: number?,
rollingExpiry: number?,
debugMode: boolean?
) → ()

Types

​

type LeaderboardType = "Hourly" | "Daily" | "Weekly" | "Monthly" | "Yearly" | "AllTime" | string

Creates a new MemoryShard. This is not a viable solution anymore, as the limits to MemoryStoreService are too poor. See: https://devforum.roblox.com/t/introducing-memorystore-sortedmap-sortkey-beta/2673559/23

Get​

This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. Yields
MemoryShard:Get(
topAmount: number,
sortDirection: string
) → {TopData}

Types

​

interface TopData {
Rank: number
UserId: number
Value: number
Username: string
DisplayName: string
}

Gets the top data from all the shards for this MemoryShard

Set​

This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. Yields
MemoryShard:Set(
userId: number,
value: number | (number) → (number)
) → boolean

Updates the value for a specific user in a specific shard

CleanupNow​

This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. Yields
MemoryShard:CleanupNow(maxEntriesPerShard: number?) → Promise.TypedPromise<boolean>

Manually triggers cleanup of excess entries from all shards. Useful for immediate cleanup when needed.

_getShardSize​

This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. Yields
MemoryShard:_getShardSize(shardIndex: number) → number

Gets the size of a specific shard.

_removeKeyFromShard​

This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. Yields
MemoryShard:_removeKeyFromShard(
shardIndex: number,
key: string
) → Promise.TypedPromise<boolean>

Removes the key from a specific shard.

Destroy​

This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. Yields
MemoryShard:Destroy() → ()

Destroys the MemoryShard

Show raw api
{
    "functions": [
        {
            "name": "_CalculateShardCount",
            "desc": "Calculates the recommended shard count based on max records.\nWarns if maxRecords exceeds 100,000 or if shardCount > 16 is recommended.",
            "params": [
                {
                    "name": "maxRecords",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "static",
            "private": true,
            "source": {
                "line": 133,
                "path": "lib/Leaderboard/Board/MemoryShard.luau"
            }
        },
        {
            "name": "new",
            "desc": "Creates a new MemoryShard. This is not a viable solution anymore, as the limits to MemoryStoreService are too poor.\nSee: https://devforum.roblox.com/t/introducing-memorystore-sortedmap-sortkey-beta/2673559/23",
            "params": [
                {
                    "name": "leaderboardType",
                    "desc": "",
                    "lua_type": "LeaderboardType"
                },
                {
                    "name": "boardKey",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "shardCount",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "maxRecords",
                    "desc": "",
                    "lua_type": "number?"
                },
                {
                    "name": "rollingExpiry",
                    "desc": "",
                    "lua_type": "number?"
                },
                {
                    "name": "debugMode",
                    "desc": "",
                    "lua_type": "boolean?"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 172,
                "path": "lib/Leaderboard/Board/MemoryShard.luau"
            }
        },
        {
            "name": "_getExpiry",
            "desc": "Gets the expiry for a specific leaderboard type and key",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number | nil"
                }
            ],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 263,
                "path": "lib/Leaderboard/Board/MemoryShard.luau"
            }
        },
        {
            "name": "_getShardKey",
            "desc": "Gets the Shard Key using prefixing and modulo",
            "params": [
                {
                    "name": "userId",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 319,
                "path": "lib/Leaderboard/Board/MemoryShard.luau"
            }
        },
        {
            "name": "_getAsync",
            "desc": "Gets the value for a specific key from a specific shard",
            "params": [
                {
                    "name": "userId",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise.TypedPromise<{TopData}>"
                }
            ],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 335,
                "path": "lib/Leaderboard/Board/MemoryShard.luau"
            }
        },
        {
            "name": "_setAsync",
            "desc": "Destroys all the shards for this MemoryShard",
            "params": [
                {
                    "name": "userId",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "any"
                },
                {
                    "name": "expiry",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "sortKey",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "()"
                }
            ],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 364,
                "path": "lib/Leaderboard/Board/MemoryShard.luau"
            }
        },
        {
            "name": "_updateAsync",
            "desc": "Updates the value for a specific key from a specific shard",
            "params": [
                {
                    "name": "userId",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "transformer",
                    "desc": "",
                    "lua_type": "(any) -> (any)"
                },
                {
                    "name": "expiry",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "()"
                }
            ],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 392,
                "path": "lib/Leaderboard/Board/MemoryShard.luau"
            }
        },
        {
            "name": "Get",
            "desc": "Gets the top data from all the shards for this MemoryShard",
            "params": [
                {
                    "name": "topAmount",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "sortDirection",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "{TopData}"
                }
            ],
            "function_type": "method",
            "yields": true,
            "source": {
                "line": 420,
                "path": "lib/Leaderboard/Board/MemoryShard.luau"
            }
        },
        {
            "name": "Set",
            "desc": "Updates the value for a specific user in a specific shard",
            "params": [
                {
                    "name": "userId",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "number | (number) -> (number)"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "method",
            "yields": true,
            "source": {
                "line": 534,
                "path": "lib/Leaderboard/Board/MemoryShard.luau"
            }
        },
        {
            "name": "CleanupNow",
            "desc": "Manually triggers cleanup of excess entries from all shards.\nUseful for immediate cleanup when needed.",
            "params": [
                {
                    "name": "maxEntriesPerShard",
                    "desc": "",
                    "lua_type": "number?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise.TypedPromise<boolean>"
                }
            ],
            "function_type": "method",
            "yields": true,
            "source": {
                "line": 584,
                "path": "lib/Leaderboard/Board/MemoryShard.luau"
            }
        },
        {
            "name": "_getShardSize",
            "desc": "Gets the size of a specific shard.",
            "params": [
                {
                    "name": "shardIndex",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "method",
            "yields": true,
            "source": {
                "line": 595,
                "path": "lib/Leaderboard/Board/MemoryShard.luau"
            }
        },
        {
            "name": "_removeKeyFromShard",
            "desc": "Removes the key from a specific shard.",
            "params": [
                {
                    "name": "shardIndex",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "key",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise.TypedPromise<boolean>"
                }
            ],
            "function_type": "method",
            "yields": true,
            "source": {
                "line": 620,
                "path": "lib/Leaderboard/Board/MemoryShard.luau"
            }
        },
        {
            "name": "_cleanupShards",
            "desc": "Cleans up excess entries from all shards to prevent storage overflow.\nRemoves the lowest-scoring entries when a shard exceeds the specified limit.",
            "params": [
                {
                    "name": "maxEntriesPerShard",
                    "desc": "",
                    "lua_type": "number?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise.TypedPromise<boolean>"
                }
            ],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 661,
                "path": "lib/Leaderboard/Board/MemoryShard.luau"
            }
        },
        {
            "name": "Destroy",
            "desc": "Destroys the MemoryShard",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "()"
                }
            ],
            "function_type": "method",
            "yields": true,
            "source": {
                "line": 769,
                "path": "lib/Leaderboard/Board/MemoryShard.luau"
            }
        }
    ],
    "properties": [],
    "types": [
        {
            "name": "LeaderboardType",
            "desc": "",
            "lua_type": "\"Hourly\" | \"Daily\" | \"Weekly\" | \"Monthly\" | \"Yearly\" | \"AllTime\" | string",
            "source": {
                "line": 30,
                "path": "lib/Leaderboard/Board/MemoryShard.luau"
            }
        },
        {
            "name": "MemoryShard",
            "desc": "",
            "lua_type": "() -> MemoryShard",
            "source": {
                "line": 36,
                "path": "lib/Leaderboard/Board/MemoryShard.luau"
            }
        },
        {
            "name": "MemoryShardArguments",
            "desc": "",
            "fields": [
                {
                    "name": "_type",
                    "lua_type": "LeaderboardType",
                    "desc": ""
                },
                {
                    "name": "_boardKey",
                    "lua_type": "string",
                    "desc": ""
                },
                {
                    "name": "_fallbackExpiry",
                    "lua_type": "number",
                    "desc": ""
                },
                {
                    "name": "_isRollingExpiry",
                    "lua_type": "boolean",
                    "desc": ""
                },
                {
                    "name": "_shards",
                    "lua_type": "{MemoryStoreSortedMap}",
                    "desc": ""
                },
                {
                    "name": "_shardCount",
                    "lua_type": "number",
                    "desc": ""
                },
                {
                    "name": "_logger",
                    "lua_type": "Logger.Logger?",
                    "desc": ""
                },
                {
                    "name": "_maxRecords",
                    "lua_type": "number",
                    "desc": ""
                }
            ],
            "source": {
                "line": 50,
                "path": "lib/Leaderboard/Board/MemoryShard.luau"
            }
        },
        {
            "name": "TopData",
            "desc": "",
            "fields": [
                {
                    "name": "Rank",
                    "lua_type": "number",
                    "desc": ""
                },
                {
                    "name": "UserId",
                    "lua_type": "number",
                    "desc": ""
                },
                {
                    "name": "Value",
                    "lua_type": "number",
                    "desc": ""
                },
                {
                    "name": "Username",
                    "lua_type": "string",
                    "desc": ""
                },
                {
                    "name": "DisplayName",
                    "lua_type": "string",
                    "desc": ""
                }
            ],
            "source": {
                "line": 72,
                "path": "lib/Leaderboard/Board/MemoryShard.luau"
            }
        },
        {
            "name": "Object",
            "desc": "",
            "fields": [
                {
                    "name": "__index",
                    "lua_type": "Object",
                    "desc": ""
                },
                {
                    "name": "_getShardKey",
                    "lua_type": "(self: MemoryShard, userId: number) -> (number)",
                    "desc": ""
                },
                {
                    "name": "_getAsync",
                    "lua_type": "(self: MemoryShard, key: string) -> any",
                    "desc": ""
                },
                {
                    "name": "_setAsync",
                    "lua_type": "(self: MemoryShard, key: string, value: any, expiry: number, sortKey: number) -> boolean",
                    "desc": ""
                },
                {
                    "name": "_updateAsync",
                    "lua_type": "(self: MemoryShard, key: string, transformer: (any) -> (any), expiry: number) -> boolean",
                    "desc": ""
                },
                {
                    "name": "_cleanupShards",
                    "lua_type": "(self: MemoryShard, maxEntriesPerShard: number?) -> Promise.TypedPromise<boolean>",
                    "desc": ""
                },
                {
                    "name": "_removeKeyFromShard",
                    "lua_type": "(self: MemoryShard, shardIndex: number, key: string) -> Promise.TypedPromise<boolean>",
                    "desc": ""
                },
                {
                    "name": "_getShardSize",
                    "lua_type": "(self: MemoryShard, shardIndex: number) -> Promise.TypedPromise<number>",
                    "desc": ""
                },
                {
                    "name": "CleanupNow",
                    "lua_type": "(self: MemoryShard, maxEntriesPerShard: number?) -> Promise.TypedPromise<boolean>",
                    "desc": ""
                },
                {
                    "name": "Set",
                    "lua_type": "(self: MemoryShard, userId: number, value: number | (number) -> (number)) -> Promise.TypedPromise<boolean>",
                    "desc": ""
                },
                {
                    "name": "Get",
                    "lua_type": "(self: MemoryShard, amount: number, sortDirection: string) -> Promise.TypedPromise<{TopData}>",
                    "desc": ""
                },
                {
                    "name": "Destroy",
                    "lua_type": "(self: MemoryShard) -> ()",
                    "desc": ""
                },
                {
                    "name": "new",
                    "lua_type": "(leaderboardType: LeaderboardType, boardKey: string, shardCount: number, maxRecords: number?, rollingExpiry: number?, debugMode: boolean?) -> MemoryShard",
                    "desc": ""
                }
            ],
            "source": {
                "line": 99,
                "path": "lib/Leaderboard/Board/MemoryShard.luau"
            }
        }
    ],
    "name": "MemoryShard",
    "desc": "A memory shard is a way to split up the leaderboard into multiple shards, each shard is a MemoryStoreSortedMap",
    "source": {
        "line": 121,
        "path": "lib/Leaderboard/Board/MemoryShard.luau"
    }
}