aboutsummaryrefslogtreecommitdiff
path: root/lib/redis.js
diff options
context:
space:
mode:
authorFactiven <[email protected]>2023-12-24 13:03:54 +0700
committerFactiven <[email protected]>2023-12-24 13:03:54 +0700
commit50a0f0240d7fef133eb5acc1bea2b1168b08e9db (patch)
tree307e09e505580415a58d64b5fc3580e9235869f1 /lib/redis.js
parentUpdate README.md (#104) (diff)
downloadmoopa-50a0f0240d7fef133eb5acc1bea2b1168b08e9db.tar.xz
moopa-50a0f0240d7fef133eb5acc1bea2b1168b08e9db.zip
migrate to typescript
Diffstat (limited to 'lib/redis.js')
-rw-r--r--lib/redis.js47
1 files changed, 0 insertions, 47 deletions
diff --git a/lib/redis.js b/lib/redis.js
deleted file mode 100644
index 9522e4c..0000000
--- a/lib/redis.js
+++ /dev/null
@@ -1,47 +0,0 @@
-import { Redis } from "ioredis";
-import { RateLimiterRedis } from "rate-limiter-flexible";
-
-const REDIS_URL = process.env.REDIS_URL;
-
-let redis;
-let rateLimiterRedis;
-let rateLimitStrict;
-let rateSuperStrict;
-
-if (REDIS_URL) {
- redis = new Redis(REDIS_URL);
- redis.on("error", (err) => {
- console.error("Redis error: ", err);
- });
-
- const opt = {
- storeClient: redis,
- keyPrefix: "rateLimit",
- points: 50,
- duration: 1,
- };
-
- const optStrict = {
- storeClient: redis,
- keyPrefix: "rateLimitStrict",
- points: 20,
- duration: 1,
- };
-
- const optSuperStrict = {
- storeClient: redis,
- keyPrefix: "rateLimitSuperStrict",
- points: 3,
- // duration 10 minutes
- duration: 10 * 60,
- blockDuration: 10 * 60,
- };
-
- rateLimiterRedis = new RateLimiterRedis(opt);
- rateLimitStrict = new RateLimiterRedis(optStrict);
- rateSuperStrict = new RateLimiterRedis(optSuperStrict);
-} else {
- console.warn("REDIS_URL is not defined. Redis caching will be disabled.");
-}
-
-export { redis, rateLimiterRedis, rateLimitStrict, rateSuperStrict };