api: add support for redis to ratelimiter cache
This commit is contained in:
19
api/src/store/redis-ratelimit.js
Normal file
19
api/src/store/redis-ratelimit.js
Normal 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),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user