Initial commit

This commit is contained in:
2026-07-18 02:10:34 +00:00
commit 21ae003ded
54 changed files with 3269 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
import { RedisClient } from "bun";
type RedisOptions = {
url: string;
options?: Bun.RedisOptions;
};
class Redis {
private client: RedisClient;
constructor(options: RedisOptions) {
this.client = new RedisClient(options.url, options.options);
}
async set(key: string, value: string, expireInSeconds?: number) {
if (expireInSeconds) {
await this.client.set(key, value, "EX", expireInSeconds);
} else {
await this.client.set(key, value);
}
}
async get<T>(key: string): Promise<T | null> {
const value = await this.client.get(key);
return value ? (JSON.parse(value) as T) : null;
}
async del(key: string) {
await this.client.del(key);
}
async exists(key: string): Promise<boolean> {
return await this.client.exists(key);
}
}
export const redis = new Redis({
url: process.env.REDIS_URL || "redis://localhost:6379",
});