fix: use Bun RedisClient type in server setup

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-13 04:50:37 +00:00
parent 3beabcfe7f
commit 8b85736903

View File

@@ -4,23 +4,17 @@ import { cors } from "hono/cors";
import { languageDetector } from "hono/language"; import { languageDetector } from "hono/language";
import isMobile from "is-mobile"; import isMobile from "is-mobile";
import { JwtProvider } from "../utils/token"; import { JwtProvider } from "../utils/token";
import { RedisClient } from "bun";
type AppFetch = ( type AppFetch = (
input: string | Request | URL, input: string | Request | URL,
requestInit?: RequestInit requestInit?: RequestInit
) => Response | Promise<Response>; ) => Response | Promise<Response>;
type RedisClientLike = {
connect(): Promise<unknown>;
get(key: string): Promise<string | null>;
set(...args: unknown[]): Promise<unknown> | unknown;
del(key: string): Promise<unknown> | unknown;
};
declare module "hono" { declare module "hono" {
interface ContextVariableMap { interface ContextVariableMap {
fetch: AppFetch; fetch: AppFetch;
isMobile: boolean; isMobile: boolean;
redis: RedisClientLike; redis: RedisClient;
jwtProvider: JwtProvider; jwtProvider: JwtProvider;
jwtPayload: Record<string, unknown>; jwtPayload: Record<string, unknown>;
userId: string; userId: string;
@@ -29,7 +23,7 @@ declare module "hono" {
} }
} }
let redisClientPromise: Promise<RedisClientLike> | null = null; let redisClientPromise: Promise<RedisClient> | null = null;
const getJwtSecret = () => { const getJwtSecret = () => {
const secret = (process.env.JWT_SECRET || process.env.STREAM_UI_JWT_SECRET || "").trim() || "secret_is_not_configured" const secret = (process.env.JWT_SECRET || process.env.STREAM_UI_JWT_SECRET || "").trim() || "secret_is_not_configured"
@@ -47,10 +41,13 @@ const getRedisUrl = () => {
return redisUrl; return redisUrl;
}; };
const getRedisClient = async (): Promise<RedisClientLike> => { const getRedisClient = async (): Promise<RedisClient> => {
console.log("bun", typeof Bun) console.log("bun", typeof Bun)
if (!redisClientPromise) { if (!redisClientPromise) {
const client = new RedisClient(getRedisUrl())
await client.connect();
return client;
// redisClientPromise = import("Bun").then(async ({ RedisClient }) => { // redisClientPromise = import("Bun").then(async ({ RedisClient }) => {
// const client = new RedisClient(getRedisUrl()) as RedisClientLike; // const client = new RedisClient(getRedisUrl()) as RedisClientLike;
// await client.connect(); // await client.connect();