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 {
_boardKeystring
_fallbackExpirynumber
_isRollingExpiryboolean
_shardCountnumber
_loggerLogger.Logger?
}

Object

interface Object {
__indexObject
_getShardKey(
selfMemoryShard,
userIdnumber
) → (number)
_getAsync(
selfMemoryShard,
keystring
) → any
_setAsync(
selfMemoryShard,
keystring,
valueany,
expirynumber,
sortKeynumber
) → boolean
_updateAsync(
selfMemoryShard,
keystring,
transformer(any) → (any),
expirynumber
) → boolean
_cleanupShards(
selfMemoryShard,
maxEntriesPerShardnumber?
) → Promise.TypedPromise<boolean>
_removeKeyFromShard(
selfMemoryShard,
shardIndexnumber,
keystring
) → Promise.TypedPromise<boolean>
_getShardSize(
selfMemoryShard,
shardIndexnumber
) → Promise.TypedPromise<number>
CleanupNow(
selfMemoryShard,
maxEntriesPerShardnumber?
) → Promise.TypedPromise<boolean>
Set(
selfMemoryShard,
userIdnumber,
valuenumber | (number) → (number)
) → Promise.TypedPromise<boolean>
Get(
selfMemoryShard,
amountnumber,
sortDirectionstring
) → Promise.TypedPromise<{TopData}>
Destroy(selfMemoryShard) → ()
new(
leaderboardTypeLeaderboardType,
boardKeystring,
shardCountnumber,
rollingExpirynumber?,
debugModeboolean?
) → MemoryShard
}

Functions

new

MemoryShard.new(
leaderboardTypeLeaderboardType,
boardKeystring,
shardCountnumber,
rollingExpirynumber?,
debugModeboolean?
) → ()

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(
topAmountnumber,
sortDirectionstring
) → {TopData}

Types

interface TopData {
Ranknumber
UserIdnumber
Valuenumber
Usernamestring
DisplayNamestring
}

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(
userIdnumber,
valuenumber | (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(maxEntriesPerShardnumber?) → 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(shardIndexnumber) → 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(
shardIndexnumber,
keystring
) → 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": "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": "rollingExpiry",
                    "desc": "",
                    "lua_type": "number?"
                },
                {
                    "name": "debugMode",
                    "desc": "",
                    "lua_type": "boolean?"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 132,
                "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": 187,
                "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": 243,
                "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": 259,
                "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": 288,
                "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": 316,
                "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": 344,
                "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": 438,
                "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": 488,
                "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": 499,
                "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": 524,
                "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": 551,
                "path": "lib/Leaderboard/Board/MemoryShard.luau"
            }
        },
        {
            "name": "Destroy",
            "desc": "Destroys the MemoryShard",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "()"
                }
            ],
            "function_type": "method",
            "yields": true,
            "source": {
                "line": 628,
                "path": "lib/Leaderboard/Board/MemoryShard.luau"
            }
        }
    ],
    "properties": [],
    "types": [
        {
            "name": "LeaderboardType",
            "desc": "",
            "lua_type": "\"Hourly\" | \"Daily\" | \"Weekly\" | \"Monthly\" | \"Yearly\" | \"AllTime\" | string",
            "source": {
                "line": 24,
                "path": "lib/Leaderboard/Board/MemoryShard.luau"
            }
        },
        {
            "name": "MemoryShard",
            "desc": "",
            "lua_type": "() -> MemoryShard",
            "source": {
                "line": 30,
                "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": ""
                }
            ],
            "source": {
                "line": 43,
                "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": 64,
                "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, rollingExpiry: number?, debugMode: boolean?) -> MemoryShard",
                    "desc": ""
                }
            ],
            "source": {
                "line": 89,
                "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": 111,
        "path": "lib/Leaderboard/Board/MemoryShard.luau"
    }
}