api: add support for redis to ratelimiter cache

This commit is contained in:
jj
2024-11-01 13:26:18 +00:00
parent d466f8a4af
commit 2317da5ba5
4 changed files with 39 additions and 1 deletions

View File

@@ -0,0 +1,19 @@
import { env } from "../config.js";
let client, redis, redisLimiter;
export const createStore = async (name) => {
if (!env.redisURL) return;
if (!client) {
redis = await import('redis');
redisLimiter = await import('rate-limit-redis');
client = redis.createClient({ url: env.redisURL });
await client.connect();
}
return new redisLimiter.default({
prefix: `RL${name}_`,
sendCommand: (...args) => client.sendCommand(args),
});
}