descript-redis-cache 3.0.0 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +12 -8
- package/index.js +13 -2
- package/package.json +1 -1
package/README.md
CHANGED
@@ -14,15 +14,19 @@ const context = new de.Context(req, res, {
|
|
14
14
|
|
15
15
|
## Config
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
}
|
24
|
-
|
17
|
+
| Param | Type | Default | Description |
|
18
|
+
|---------------|-----------------------------------|----------------|--------------------------------------------------------------|
|
19
|
+
| clusterNodes | `Array` | `[]` | If you're using a cluster: an array of nodes in the cluster `[{ port: number, host: string }]` |
|
20
|
+
| defaultKeyTTL | `number` | `60 * 60 * 24` | key ttl in seconds |
|
21
|
+
| generation | `number` | 1 | increment generation to invalidate all key across breaking changes releases |
|
22
|
+
| readTimeout | `number` | 100 | read timeout in milliseconds |
|
23
|
+
| redisOptions | `IRedisOptions` or `IClusterOptions` | `{}` | Redis constructor [options](https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options) or Redis.Cluster constructor [options](https://github.com/luin/ioredis/blob/master/API.md#new-clusterstartupnodes-options) |
|
24
|
+
| useCluster | `boolean` | false | to use [Redis.Cluster](#Cluster) |
|
25
|
+
|
25
26
|
|
26
27
|
## Logger
|
27
28
|
|
28
29
|
Optionally you can pass logger object in the constructor. It should implement standard `Console` methods.
|
30
|
+
|
31
|
+
## Cluster
|
32
|
+
It also has a support for Redis Cluster. In this case you should pass `useCluster = true`, an array of `clusterNodes` and also [clusterOptions](https://github.com/luin/ioredis/blob/a46415187d32bfdc974072403edb8aca2df282d6/lib/cluster/ClusterOptions.ts#L30) in `redisOptions`.
|
package/index.js
CHANGED
@@ -9,19 +9,30 @@ class DescriptRedisCache {
|
|
9
9
|
|
10
10
|
constructor(options, logger) {
|
11
11
|
this._options = Object.assign({
|
12
|
+
clusterNodes: [],
|
12
13
|
defaultKeyTTL: 60 * 60 * 24, // key ttl in seconds
|
13
14
|
generation: 1, // increment generation to invalidate all key across breaking changes releases
|
14
15
|
readTimeout: 100, // read timeout in milliseconds,
|
15
16
|
redisOptions: {},
|
17
|
+
useCluster: false,
|
16
18
|
}, options);
|
17
19
|
|
18
20
|
this._logger = logger;
|
19
21
|
|
20
|
-
|
22
|
+
if (this._options.useCluster) {
|
23
|
+
this._client = new Redis.Cluster(this._options.clusterNodes, this._options.redisOptions);
|
24
|
+
} else {
|
25
|
+
this._client = new Redis(this._options.redisOptions);
|
26
|
+
}
|
27
|
+
|
28
|
+
const optionsToLog = Object.assign({}, this._options);
|
29
|
+
// Don't write connection options to log because it can contain password
|
30
|
+
// (not only as a property, but as a part of a connection string, so it's difficult to delete only a password)
|
31
|
+
delete optionsToLog.redisOptions;
|
21
32
|
|
22
33
|
this._log({
|
23
34
|
type: DescriptRedisCache.EVENT.REDIS_CACHE_INITIALIZED,
|
24
|
-
options:
|
35
|
+
options: optionsToLog,
|
25
36
|
});
|
26
37
|
}
|
27
38
|
|