@tekir/cache 0.1.4 → 0.1.6
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/dist/stores/redis.d.ts +1 -3
- package/dist/stores/redis.js +5 -1
- package/package.json +1 -1
- package/src/stores/redis.ts +17 -5
package/dist/stores/redis.d.ts
CHANGED
|
@@ -3,10 +3,8 @@ 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
|
-
send(command: string, args: unknown[]): Promise<unknown>;
|
|
9
|
-
connected?: boolean;
|
|
10
8
|
}
|
|
11
9
|
/**
|
|
12
10
|
* Redis-backed cache store with key prefixing and optional TTL.
|
package/dist/stores/redis.js
CHANGED
|
@@ -80,7 +80,9 @@ export class RedisCacheStore {
|
|
|
80
80
|
* ```
|
|
81
81
|
*/
|
|
82
82
|
async has(key) {
|
|
83
|
-
|
|
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.
|
|
@@ -107,6 +109,8 @@ export class RedisCacheStore {
|
|
|
107
109
|
* ```
|
|
108
110
|
*/
|
|
109
111
|
async flush() {
|
|
112
|
+
// Structural cast: callers may pass clients with varying `send` arg
|
|
113
|
+
// types. We only need it to accept a string command and an array.
|
|
110
114
|
await this.redis.send('FLUSHDB', []);
|
|
111
115
|
}
|
|
112
116
|
}
|
package/package.json
CHANGED
package/src/stores/redis.ts
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import type { CacheStore } from '../types'
|
|
2
2
|
|
|
3
|
+
// Lean shape: only the calls the cache store actually makes. `send` is
|
|
4
|
+
// intentionally absent because raw command shapes vary across clients
|
|
5
|
+
// (`@tekir/redis` typed string-only, ioredis any[], node-redis unknown[]).
|
|
6
|
+
// `flush()` invokes it through a structural cast so any client works.
|
|
3
7
|
interface RedisClient {
|
|
4
8
|
get(key: string): Promise<string | null>
|
|
5
9
|
set(key: string, value: string): Promise<unknown>
|
|
6
10
|
expire(key: string, seconds: number): Promise<unknown>
|
|
7
|
-
|
|
11
|
+
// Accept both `Promise<boolean>` (@tekir/redis) and `Promise<number>`
|
|
12
|
+
// (node-redis, ioredis). Normalised at the call site.
|
|
13
|
+
exists(key: string): Promise<boolean | number>
|
|
8
14
|
del(key: string): Promise<unknown>
|
|
9
|
-
|
|
10
|
-
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface RawSendable {
|
|
18
|
+
send(command: string, args?: unknown[]): Promise<unknown>
|
|
11
19
|
}
|
|
12
20
|
|
|
13
21
|
/**
|
|
@@ -89,7 +97,9 @@ export class RedisCacheStore implements CacheStore {
|
|
|
89
97
|
* ```
|
|
90
98
|
*/
|
|
91
99
|
async has(key: string): Promise<boolean> {
|
|
92
|
-
|
|
100
|
+
// Coerces both shapes: @tekir/redis returns boolean, node-redis/ioredis
|
|
101
|
+
// return number. `!!0` → false, `!!1` → true, `!!true` → true.
|
|
102
|
+
return !!(await this.redis.exists(this.prefix + key))
|
|
93
103
|
}
|
|
94
104
|
|
|
95
105
|
/**
|
|
@@ -118,6 +128,8 @@ export class RedisCacheStore implements CacheStore {
|
|
|
118
128
|
* ```
|
|
119
129
|
*/
|
|
120
130
|
async flush(): Promise<void> {
|
|
121
|
-
|
|
131
|
+
// Structural cast: callers may pass clients with varying `send` arg
|
|
132
|
+
// types. We only need it to accept a string command and an array.
|
|
133
|
+
await (this.redis as unknown as RawSendable).send('FLUSHDB', [])
|
|
122
134
|
}
|
|
123
135
|
}
|