Hoshimi
Guides

Queue and Storage

Queue operations, persistence strategy and custom storage adapters.

This guide combines queue usage with storage patterns used in the example bot. It is designed to keep queue state consistent across reconnects and restarts.

Type reference: Core API (TypeDoc)

Quick links:

Queue Operations

queue-ops.ts
import type { ,  } from 'hoshimi';

declare const : ;
declare const : ;

const  = .;

if (.()) {
  // nothing queued yet
}

await .();
const  = await .();

.(.);
.(.);
.(.);
.(..);

await .();
await .(0, 1);
await .();

In-Memory Defaults

memory-storage.ts
import { ,  } from 'hoshimi';

const  = new ();
const  = new ();

. = 'hoshimiplayer';
. = 'hoshimiqueue';

Redis Queue Adapter (Real Pattern)

redis-queue-adapter.ts
import type { QueueJson,  } from 'hoshimi';
import {  } from 'hoshimi';

interface RedisLike {
  (: string): <string | null>;
  (: string, : string): <void>;
  (: string): <number>;
  (: string): <number>;
}

class  extends  {
  constructor(private readonly : RedisLike) {
    super();
  }

  override async (: string): <QueueJson | undefined> {
    const  = await this..(this.(this., ));
    return  ? this.() : ;
  }

  override async (: string, : QueueJson): <void> {
    await this..(this.(this., ), this.());
  }

  override async (: string): <boolean> {
    return (await this..(this.(this., ))) > 0;
  }

  override async (: string): <boolean> {
    return (await this..(this.(this., ))) > 0;
  }

  override async (): <void> {
    // implement according to your redis strategy
  }

  override (: unknown): QueueJson {
    return typeof  === "string" ? .() : ( as QueueJson);
  }

  override < = string>(: unknown):  {
    return (typeof  === "object" ? .() : ) as ;
  }

  public (...: <string>): string {
    const  = .();
    return .(":");
  }
}

Practical Persistence Notes

  • Persist only what you can safely replay (voiceId, textId, queue data, node session info).
  • Store feature flags in player storage (enabledAutoplay, enabledLyrics).
  • Clear lyric/session keys on PlayerDestroy and QueueEnd to avoid stale messages.

On this page