web-gatekeeper-js 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-gatekeeper-js",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Redis based rate limiter and throttler using sliding window and token bucket algorithms",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -1,16 +1,33 @@
1
+ // src/store/RedisStore.js
2
+
1
3
  export class RedisStore {
2
4
  #redis
5
+ #isIoRedis
3
6
 
4
7
  constructor(redisClient) {
5
- this.#redis = redisClient
8
+ this.#redis = redisClient
9
+
10
+ // detect which client is being used
11
+ this.#isIoRedis = redisClient.constructor.name === 'Redis'
6
12
  }
7
13
 
8
14
  async evalScript(script, key, ...args) {
9
- return await this.#redis.eval(
10
- script,
11
- 1,
12
- key,
13
- ...args
14
- )
15
+
16
+ // ioredis syntax
17
+ if (this.#isIoRedis) {
18
+ return await this.#redis.eval(
19
+ script,
20
+ 1,
21
+ key,
22
+ ...args
23
+ )
24
+ }
25
+
26
+ // redis package syntax
27
+ return await this.#redis.eval(script, {
28
+ numKeys : 1,
29
+ keys : [key],
30
+ arguments : args.map(String)
31
+ })
15
32
  }
16
33
  }