QueueStoreManager
Please Note, the Queue is always "cached" on the client side, which means it's still quite fast, however, the speed of "saving and syncing" depends on the StoreManager.
Here is a List of External Stores I'd recommend:
DragonflyDB (Redis Remake, but for bigger scale and it's quite faster than redis)
Redis (Good old Key-Value Database)
Memcached (old alternative to Redis)
PostgresQL via citus-data clusters (SQL Database for high work-flow)
SingleStore (New SQL Database)
Overview
Parameter
Type
Required
Description
get
β
set
β
delete
β
stringify
β
parse
β
The interface `QueueStoreManager` declares, what methods your custom QueueStore requires!
export interface QueueStoreManager extends Record<string, any>{
/** @async get a Value (MUST RETURN UNPARSED!) */
get: (guildId: unknown) => Promise<any>;
/** @async Set a value inside a guildId (MUST BE UNPARSED) */
set: (guildId: unknown, value: unknown) => Promise<any>;
/** @async Delete a Database Value based of it's guildId */
delete: (guildId: unknown) => Promise<any>;
/** @async Transform the value(s) inside of the QueueStoreManager (IF YOU DON'T NEED PARSING/STRINGIFY, then just return the value) */
stringify: (value: unknown) => Promise<any>;
/** @async Parse the saved value back to the Queue (IF YOU DON'T NEED PARSING/STRINGIFY, then just return the value) */
parse: (value: unknown) => Promise<Partial<StoredQueue>>;
}
Examples:
Example Queue Store Manager:
This is also the Default Queue Store, which you can import from lavalink-client!
export class myCustomStore implements QueueStoreManager {
private redis:RedisClientType;
constructor(redisClient:RedisClientType) {
this.redis = redisClient;
}
async get(guildId): Promise<any> {
return await this.redis.get(this.id(guildId));
}
async set(guildId, stringifiedQueueData): Promise<any> {
// await this.delete(guildId); // redis requires you to delete it first;
return await this.redis.set(this.id(guildId), stringifiedQueueData);
}
async delete(guildId): Promise<any> {
return await this.redis.del(this.id(guildId));
}
async parse(stringifiedQueueData): Promise<Partial<StoredQueue>> {
return JSON.parse(stringifiedQueueData);
}
async stringify(parsedQueueData): Promise<any> {
return JSON.stringify(parsedQueueData);
}
// you can add more utils if you need to...
private id(guildId) {
return `lavalinkqueue_${guildId}`; // transform the id
}
}
Example for Redis:
export class myCustomStore implements QueueStoreManager {
private redis:RedisClientType;
constructor(redisClient:RedisClientType) {
this.redis = redisClient;
}
async get(guildId): Promise<any> {
return await this.redis.get(guildId);
}
async set(guildId, stringifiedQueueData): Promise<any> {
// await this.delete(guildId); // some redis versions (especially on hset) requires you to delete it first;
return await this.redis.set(guildId, stringifiedQueueData);
}
async delete(guildId): Promise<any> {
return await this.redis.del(guildId);
}
async parse(stringifiedQueueData): Promise<Partial<StoredQueue>> {
return JSON.parse(stringifiedQueueData);
}
async stringify(parsedQueueData): Promise<any> {
return JSON.stringify(parsedQueueData);
}
}
Last updated