@midwayjs/redis 3.13.9 → 3.14.0

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.
@@ -1,5 +1,7 @@
1
- export declare class RedisConfiguration {
2
- onReady(container: any): Promise<void>;
3
- onStop(container: any): Promise<void>;
1
+ import { HealthResult, ILifeCycle, IMidwayContainer } from '@midwayjs/core';
2
+ export declare class RedisConfiguration implements ILifeCycle {
3
+ onReady(container: IMidwayContainer): Promise<void>;
4
+ onStop(container: IMidwayContainer): Promise<void>;
5
+ onHealthCheck(container: IMidwayContainer): Promise<HealthResult>;
4
6
  }
5
7
  //# sourceMappingURL=configuration.d.ts.map
@@ -17,6 +17,22 @@ let RedisConfiguration = class RedisConfiguration {
17
17
  const factory = await container.getAsync(manager_1.RedisServiceFactory);
18
18
  await factory.stop();
19
19
  }
20
+ async onHealthCheck(container) {
21
+ const factory = await container.getAsync(manager_1.RedisServiceFactory);
22
+ const clients = factory.getClients();
23
+ // find status not ready
24
+ let clientName;
25
+ for (const [name, instance] of clients) {
26
+ if (instance.status !== 'ready' && !factory.isLowPriority(name)) {
27
+ clientName = name;
28
+ break;
29
+ }
30
+ }
31
+ return {
32
+ status: !clientName,
33
+ reason: clientName ? `redis client "${clientName}" is not ready` : '',
34
+ };
35
+ }
20
36
  };
21
37
  RedisConfiguration = __decorate([
22
38
  (0, core_1.Configuration)({
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
+ import Redis from 'ioredis';
1
2
  export { RedisConfiguration as Configuration } from './configuration';
2
3
  export * from './manager';
3
4
  export * from './interface';
5
+ export { Redis };
4
6
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -14,7 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.Configuration = void 0;
17
+ exports.Redis = exports.Configuration = void 0;
18
+ const ioredis_1 = require("ioredis");
19
+ exports.Redis = ioredis_1.default;
18
20
  var configuration_1 = require("./configuration");
19
21
  Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.RedisConfiguration; } });
20
22
  __exportStar(require("./manager"), exports);
package/dist/manager.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { ServiceFactory, ServiceFactoryConfigOption } from '@midwayjs/core';
1
+ import { ServiceFactory, ServiceFactoryConfigOption, ILogger } from '@midwayjs/core';
2
2
  import Redis from 'ioredis';
3
3
  import { RedisConfigOptions } from './interface';
4
4
  export declare class RedisServiceFactory extends ServiceFactory<Redis> {
5
- redisConfig: ServiceFactoryConfigOption<RedisConfigOptions>;
6
- init(): Promise<void>;
7
- logger: any;
8
- createClient(config: any): Promise<Redis>;
5
+ protected redisConfig: ServiceFactoryConfigOption<RedisConfigOptions>;
6
+ protected init(): Promise<void>;
7
+ protected logger: ILogger;
8
+ protected createClient(config: any): Promise<Redis>;
9
9
  getName(): string;
10
- destroyClient(redisInstance: any): Promise<void>;
10
+ protected destroyClient(redisInstance: any): Promise<void>;
11
11
  }
12
12
  export declare class RedisService implements Redis {
13
13
  private serviceFactory;
package/dist/manager.js CHANGED
@@ -57,7 +57,12 @@ let RedisServiceFactory = class RedisServiceFactory extends core_1.ServiceFactor
57
57
  }
58
58
  async destroyClient(redisInstance) {
59
59
  try {
60
- await (redisInstance && redisInstance.quit());
60
+ if (redisInstance) {
61
+ const canQuit = !['end', 'close'].includes(redisInstance.status);
62
+ if (canQuit) {
63
+ await redisInstance.quit();
64
+ }
65
+ }
61
66
  }
62
67
  catch (error) {
63
68
  this.logger.error('[midway:redis] Redis quit failed.', error);
package/index.d.ts CHANGED
@@ -1,7 +1,4 @@
1
- import { ClusterNode, ClusterOptions } from 'ioredis';
2
- import * as Redis from 'ioredis';
3
1
  import { RedisConfigOptions } from './dist';
4
-
5
2
  export * from './dist/index';
6
3
 
7
4
  // Single Redis
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@midwayjs/redis",
3
3
  "description": "midway redis component",
4
- "version": "3.13.9",
4
+ "version": "3.14.0",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
7
7
  "files": [
@@ -10,8 +10,8 @@
10
10
  "index.d.ts"
11
11
  ],
12
12
  "devDependencies": {
13
- "@midwayjs/core": "^3.13.7",
14
- "@midwayjs/mock": "^3.13.9"
13
+ "@midwayjs/core": "^3.14.0",
14
+ "@midwayjs/mock": "^3.14.0"
15
15
  },
16
16
  "dependencies": {
17
17
  "ioredis": "5.3.2"
@@ -35,5 +35,5 @@
35
35
  "type": "git",
36
36
  "url": "https://github.com/midwayjs/midway.git"
37
37
  },
38
- "gitHead": "00750219506f4e3ad0e1dbb167d295610005b328"
38
+ "gitHead": "67e3a3596ffdb65a413064d30c68f1f7965af282"
39
39
  }