descript-redis-cache 4.0.2 → 4.0.3
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/README.md +12 -4
- package/build/index.d.ts +2 -0
- package/build/index.js +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
@@ -5,15 +5,23 @@ Plugin to use Redis as a cache in Descript
|
|
5
5
|
|
6
6
|
```js
|
7
7
|
import de from 'descript';
|
8
|
-
import
|
8
|
+
import { Cache } from 'descript-redis-cache';
|
9
9
|
|
10
|
-
const redisCache = new
|
10
|
+
const redisCache = new Cache(options);
|
11
|
+
|
12
|
+
// subscribe to events if necessary
|
13
|
+
// @see https://github.com/luin/ioredis#connection-events
|
14
|
+
redisCache.getClient()
|
15
|
+
.on('reconnecting', () => {/* ... */})
|
16
|
+
.on('error', () => {/* ... */})
|
17
|
+
.on('close', () => {/* ... */})
|
18
|
+
.on('end', () => {/* ... */});
|
11
19
|
|
12
20
|
const myBlock = de.http({
|
13
21
|
block: { /* ... */ },
|
14
22
|
options: {
|
15
|
-
key: ({ params }) => '
|
16
|
-
cache:
|
23
|
+
key: ({ params }) => '_some_cache_key_by_params_',
|
24
|
+
cache: redisCache,
|
17
25
|
}
|
18
26
|
});
|
19
27
|
```
|
package/build/index.d.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import type { CacheInterface } from 'descript';
|
2
2
|
import type { ClusterNode, ClusterOptions, RedisOptions } from 'ioredis';
|
3
|
+
import { Cluster, Redis } from 'ioredis';
|
3
4
|
export interface Options {
|
4
5
|
defaultKeyTTL?: number;
|
5
6
|
generation?: number;
|
@@ -108,6 +109,7 @@ export type LoggerEvent = ({
|
|
108
109
|
export declare class Cache<Result> implements CacheInterface<Result> {
|
109
110
|
#private;
|
110
111
|
constructor(options: Options, logger?: Logger);
|
112
|
+
getClient(): Cluster | Redis;
|
111
113
|
get({ key }: {
|
112
114
|
key: string;
|
113
115
|
}): Promise<Result | undefined>;
|
package/build/index.js
CHANGED
@@ -43,6 +43,9 @@ class Cache {
|
|
43
43
|
options: { ...__classPrivateFieldGet(this, _Cache_options, "f") },
|
44
44
|
});
|
45
45
|
}
|
46
|
+
getClient() {
|
47
|
+
return __classPrivateFieldGet(this, _Cache_client, "f");
|
48
|
+
}
|
46
49
|
get({ key }) {
|
47
50
|
const normalizedKey = __classPrivateFieldGet(this, _Cache_instances, "m", _Cache_normalizeKey).call(this, key);
|
48
51
|
return new Promise((resolve, reject) => {
|