@tekir/cache 0.1.4 → 0.1.5

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.
@@ -3,7 +3,7 @@ interface RedisClient {
3
3
  get(key: string): Promise<string | null>;
4
4
  set(key: string, value: string): Promise<unknown>;
5
5
  expire(key: string, seconds: number): Promise<unknown>;
6
- exists(key: string): Promise<number>;
6
+ exists(key: string): Promise<boolean | number>;
7
7
  del(key: string): Promise<unknown>;
8
8
  send(command: string, args: unknown[]): Promise<unknown>;
9
9
  connected?: boolean;
@@ -80,7 +80,9 @@ export class RedisCacheStore {
80
80
  * ```
81
81
  */
82
82
  async has(key) {
83
- return (await this.redis.exists(this.prefix + key)) > 0;
83
+ // Coerces both shapes: @tekir/redis returns boolean, node-redis/ioredis
84
+ // return number. `!!0` → false, `!!1` → true, `!!true` → true.
85
+ return !!(await this.redis.exists(this.prefix + key));
84
86
  }
85
87
  /**
86
88
  * Delete a key from Redis.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tekir/cache",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "In-memory, Redis, and database caching abstraction",
5
5
  "author": "dev@tekir.io",
6
6
  "license": "MIT",
@@ -4,7 +4,9 @@ interface RedisClient {
4
4
  get(key: string): Promise<string | null>
5
5
  set(key: string, value: string): Promise<unknown>
6
6
  expire(key: string, seconds: number): Promise<unknown>
7
- exists(key: string): Promise<number>
7
+ // Accept both `Promise<boolean>` (@tekir/redis) and `Promise<number>`
8
+ // (node-redis, ioredis). Normalised at the call site.
9
+ exists(key: string): Promise<boolean | number>
8
10
  del(key: string): Promise<unknown>
9
11
  send(command: string, args: unknown[]): Promise<unknown>
10
12
  connected?: boolean
@@ -89,7 +91,9 @@ export class RedisCacheStore implements CacheStore {
89
91
  * ```
90
92
  */
91
93
  async has(key: string): Promise<boolean> {
92
- return (await this.redis.exists(this.prefix + key)) > 0
94
+ // Coerces both shapes: @tekir/redis returns boolean, node-redis/ioredis
95
+ // return number. `!!0` → false, `!!1` → true, `!!true` → true.
96
+ return !!(await this.redis.exists(this.prefix + key))
93
97
  }
94
98
 
95
99
  /**