Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Useparagon cluster support #4

Merged
merged 9 commits into from
Nov 6, 2020
Merged
219 changes: 0 additions & 219 deletions README.md

This file was deleted.

11 changes: 11 additions & 0 deletions dist/cluster-core.module.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { DynamicModule, OnModuleDestroy } from '@nestjs/common';
import { ModuleRef } from '@nestjs/core';
import { RedisClusterModuleAsyncOptions, RedisClusterModuleOptions } from './cluster.interface';
export declare class ClusterCoreModule implements OnModuleDestroy {
private readonly options;
private readonly moduleRef;
constructor(options: RedisClusterModuleOptions | RedisClusterModuleOptions[], moduleRef: ModuleRef);
static register(options: RedisClusterModuleOptions | RedisClusterModuleOptions[]): DynamicModule;
static forRootAsync(options: RedisClusterModuleAsyncOptions): DynamicModule;
onModuleDestroy(): void;
}
72 changes: 72 additions & 0 deletions dist/cluster-core.module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
var ClusterCoreModule_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClusterCoreModule = void 0;
const common_1 = require("@nestjs/common");
const core_1 = require("@nestjs/core");
const cluster_provider_1 = require("./cluster.provider");
const cluster_constants_1 = require("./cluster.constants");
const cluster_service_1 = require("./cluster.service");
let ClusterCoreModule = ClusterCoreModule_1 = class ClusterCoreModule {
constructor(options, moduleRef) {
this.options = options;
this.moduleRef = moduleRef;
}
static register(options) {
return {
module: ClusterCoreModule_1,
providers: [
cluster_provider_1.createCluster(),
{ provide: cluster_constants_1.REDIS_CLUSTER_MODULE_OPTIONS, useValue: options },
],
exports: [cluster_service_1.RedisClusterService],
};
}
static forRootAsync(options) {
return {
module: ClusterCoreModule_1,
imports: options.imports,
providers: [cluster_provider_1.createCluster(), cluster_provider_1.createAsyncClusterOptions(options)],
exports: [cluster_service_1.RedisClusterService],
};
}
onModuleDestroy() {
const closeConnection = ({ clusters, defaultKey, }) => options => {
const name = options.name || defaultKey;
const cluster = clusters.get(name);
if (cluster && !options.keepAlive) {
cluster.disconnect();
}
};
const provider = this.moduleRef.get(cluster_constants_1.REDIS_CLUSTER);
const closeClusterConnection = closeConnection(provider);
if (Array.isArray(this.options)) {
this.options.forEach(closeClusterConnection);
}
else {
closeClusterConnection(this.options);
}
}
};
ClusterCoreModule = ClusterCoreModule_1 = __decorate([
common_1.Global(),
common_1.Module({
providers: [cluster_service_1.RedisClusterService],
exports: [cluster_service_1.RedisClusterService],
}),
__param(0, common_1.Inject(cluster_constants_1.REDIS_CLUSTER_MODULE_OPTIONS)),
__metadata("design:paramtypes", [Object, core_1.ModuleRef])
], ClusterCoreModule);
exports.ClusterCoreModule = ClusterCoreModule;
2 changes: 2 additions & 0 deletions dist/cluster.constants.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export declare const REDIS_CLUSTER_MODULE_OPTIONS: unique symbol;
export declare const REDIS_CLUSTER: unique symbol;
5 changes: 5 additions & 0 deletions dist/cluster.constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.REDIS_CLUSTER = exports.REDIS_CLUSTER_MODULE_OPTIONS = void 0;
exports.REDIS_CLUSTER_MODULE_OPTIONS = Symbol('REDIS_CLUSTER_MODULE_OPTIONS');
exports.REDIS_CLUSTER = Symbol('REDIS_CLUSTER');
11 changes: 11 additions & 0 deletions dist/cluster.interface.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ModuleMetadata } from '@nestjs/common/interfaces';
import { Redis, ClusterOptions } from 'ioredis';
export interface RedisClusterModuleOptions extends ClusterOptions {
name?: string;
nodes: (string | number | object)[];
onClusterReady?(cluster: Redis): Promise<void>;
}
export interface RedisClusterModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
useFactory?: (...args: any[]) => RedisClusterModuleOptions | RedisClusterModuleOptions[] | Promise<RedisClusterModuleOptions> | Promise<RedisClusterModuleOptions[]>;
inject?: any[];
}
2 changes: 2 additions & 0 deletions dist/cluster.interface.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
6 changes: 6 additions & 0 deletions dist/cluster.module.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { DynamicModule } from '@nestjs/common';
import { RedisClusterModuleAsyncOptions, RedisClusterModuleOptions } from './cluster.interface';
export declare class RedisClusterModule {
static register(options: RedisClusterModuleOptions | RedisClusterModuleOptions[]): DynamicModule;
static forRootAsync(options: RedisClusterModuleAsyncOptions): DynamicModule;
}
30 changes: 30 additions & 0 deletions dist/cluster.module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var RedisClusterModule_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RedisClusterModule = void 0;
const common_1 = require("@nestjs/common");
const cluster_core_module_1 = require("./cluster-core.module");
let RedisClusterModule = RedisClusterModule_1 = class RedisClusterModule {
static register(options) {
return {
module: RedisClusterModule_1,
imports: [cluster_core_module_1.ClusterCoreModule.register(options)],
};
}
static forRootAsync(options) {
return {
module: RedisClusterModule_1,
imports: [cluster_core_module_1.ClusterCoreModule.forRootAsync(options)],
};
}
};
RedisClusterModule = RedisClusterModule_1 = __decorate([
common_1.Module({})
], RedisClusterModule);
exports.RedisClusterModule = RedisClusterModule;
16 changes: 16 additions & 0 deletions dist/cluster.provider.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Redis } from 'ioredis';
import { Provider } from '@nestjs/common';
import { RedisClusterModuleAsyncOptions, RedisClusterModuleOptions } from './cluster.interface';
export declare class RedisClusterError extends Error {
}
export interface RedisClusterProvider {
defaultKey: string;
clusters: Map<string, Redis>;
size: number;
}
export declare const createCluster: () => Provider;
export declare const createAsyncClusterOptions: (options: RedisClusterModuleAsyncOptions) => {
provide: symbol;
useFactory: (...args: any[]) => RedisClusterModuleOptions | Promise<RedisClusterModuleOptions> | RedisClusterModuleOptions[] | Promise<RedisClusterModuleOptions[]>;
inject: any[];
};
Loading