PlayerMemoryStorage

Class representing a player storage.

Signature

export declare class PlayerMemoryStorage<K extends StorageKeys = StorageKeys, V extends StorageValues<K> = StorageValues<K>> extends PlayerStorageAdapter

JSDoc

@classPlayerMemoryStorage@extendsPlayerStorageAdapter

Methods

get<K extends StorageKeys, V extends StorageValues<K>>(key: K): Awaitable<V | undefined>;

Get the value using the key.

Parameters

key
The key to get the value from.

Returns

The value of the key.

Examples

const value = await storage.get("key");
console.log(value); // "value"
set<K extends StorageKeys, V extends StorageValues<K>>(key: K, value: V): Awaitable<void>;

Set the value using the key.

Parameters

key
The key to set the value to.
value
The value to set.

Returns

Did you know this can be async?

Examples

await storage.set("key", "value");
has<K extends StorageKeys>(key: K): Awaitable<boolean>;

Check if the storage has the key.

Parameters

key
The key to check.

Returns

Return true if the key exists.

Examples

const exists = await storage.has("key");
console.log(exists); // true
delete<K extends StorageKeys>(key: K): Awaitable<boolean>;

Delete the value using the key.

Parameters

key
The key to delete the value from.

Returns

Returns true if the key was deleted.

Examples

const success = await storage.delete("key");
console.log(success); // true
keys<K extends StorageKeys[]>(): Awaitable<K[]>;

Get all keys in the storage.

Returns

The keys in the storage.

Examples

const keys = await storage.keys();
console.log(keys); // ["key1", "key2"]
values<K extends StorageKeys[], V extends StorageValues<K[number]>>(): Awaitable<V[]>;

Get all values in the storage.

Returns

The values in the storage.

Examples

const values = await storage.values();
console.log(values); // ["value1", "value2"]
entries<K extends StorageKeys[], V extends StorageValues<K[number]>>(): Awaitable<[    K,    V][]>;

Get all entries in the storage.

Returns

The entries in the storage.

Examples

const entries = await storage.entries();
console.log(entries); // [["key1", "value1"], ["key2", "value2"]]
all<K extends StorageKeys[], V extends StorageValues<K[number]>>(): Awaitable<Record<K[number], V>>;

Get all key-value pairs in the storage.

Returns

An object containing all key-value pairs in the storage, excluding internal keys.

Examples

const all = await storage.all();
console.log(all); // { key1: "value1", key2: "value2" }
setIfAbsent<K extends StorageKeys, V extends StorageValues<K>>(key: K, value: V): boolean;

Set the value if the key does not exist in the storage.

Parameters

key
The key to set the value to if it does not exist.
value
The value to set if the key does not exist.

Returns

Returns true if the value was set, false if the key already exists.

Examples

const success = await storage.setIfAbsent("key", "value");
console.log(success); // true

const success2 = await storage.setIfAbsent("key", "newValue");
console.log(success2); // false

const value = await storage.get("key");
console.log(value); // "value"
clear(): Awaitable<void>;

Clear the storage.

Returns

Scary, right?

Examples

await storage.clear();
size(): Awaitable<number>;

Get the size of the storage.

Returns

The size of the storage.

Examples

const size = await storage.size();
console.log(size); // 2
destroy(): Awaitable<void>;

Destroy the storage. This is called when the player is destroyed.

Returns

Did you know this can be async?

Examples

await storage.destroy();