Lavalink-Client
  • 😁Lavalink Client
  • Basics
    • How it works
    • Get Started
    • Example Discord Bot
  • Documentation
    • LavalinkManager
      • Manager Options
        • ManagerQueueOptions
          • QueueStoreManager
          • QueueChangesWatcher
        • ManagerPlayerOptions
          • RequestTransformer
          • AutoplayFunction
        • BotClientOptions
      • ManagerUtils
    • NodeManager
      • Types
        • LavalinkNode
        • LavalinkNodeOptions
    • Player
      • PlayerOptions
      • PlayerDestroyReasons
      • PlayerTypes
        • RepeatMode
        • PlayerJson
    • Other Types
      • EQBand
      • FilterData
        • KaraokeFilter
      • Track
        • TrackInfo
        • PluginInfo
      • UnresolvedTrack
      • UnresolvedQuery
      • LavalinkTrack
        • Base64
        • LavalinkTrackInfo
      • Payloads
        • GuildShardPayload
        • PlayerEvent
        • TrackStartEvent
        • TrackEndEvent
        • TrackStuckEvent
        • TrackExceptionEvent
        • WebSocketClosedEvent
      • SearchPlatform
        • LavalinkSearchPlatform
        • ClientSearchPlatform
      • SourceNames
        • LavalinkSourceNames
        • LavaSrc SourceNames (lavalink-plugin)
    • Other Utils and Classes
      • DefaultQueueStore
      • MiniMap
  • Requirements
  • Host a Lavalink-Server
    • application.yml Configuration
      • With Spotify, Deezer, Apple Music, etc.
    • Host via pm2
    • Host via systemd
    • Host via screen
  • ⚪Github
  • 📖Lavalink-Support Server
Powered by GitBook
On this page
  • Overview
  • Examples:
  • Example Queue Store Manager:
  • Example for Redis:
  1. Documentation
  2. LavalinkManager
  3. Manager Options
  4. ManagerQueueOptions

QueueStoreManager

PreviousManagerQueueOptionsNextQueueChangesWatcher

Last updated 1 year ago

Type: /

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:

  • (Redis Remake, but for bigger scale and it's quite faster than redis)

  • (Good old Key-Value Database)

  • (old alternative to Redis)

  • via (SQL Database for high work-flow)

  • (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);
    }
}

class
object
DragonflyDB
Redis
Memcached
PostgresQL
citus-data clusters
SingleStore
Default one (MiniMap)
External one (Redis)