nestjs-redis-cluster
Advanced tools
Comparing version 2.0.8 to 2.1.0-experimental
@@ -48,3 +48,3 @@ "use strict"; | ||
const cluster = clusters.get(name); | ||
if (cluster && !options.keepAlive) { | ||
if (cluster && !options.disableDisconnectOnShutdown) { | ||
cluster.disconnect(); | ||
@@ -51,0 +51,0 @@ } |
@@ -8,2 +8,3 @@ import { ModuleMetadata } from '@nestjs/common/interfaces'; | ||
onClusterReady?(cluster: IORedis.Cluster): Promise<void>; | ||
disableDisconnectOnShutdown?: boolean; | ||
} | ||
@@ -10,0 +11,0 @@ export interface RedisClusterModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> { |
import * as IORedis from 'ioredis'; | ||
import { RedisClusterProvider } from './cluster.provider'; | ||
import { RedisClusterModuleOptions } from './cluster.interface'; | ||
export declare class RedisClusterService { | ||
private readonly provider; | ||
constructor(provider: RedisClusterProvider); | ||
private readonly options; | ||
constructor(provider: RedisClusterProvider, options: RedisClusterModuleOptions | RedisClusterModuleOptions[]); | ||
getCluster(name?: string): IORedis.Cluster; | ||
getClusters(): Map<string, IORedis.Cluster>; | ||
disconnectAllClients(): void; | ||
} |
@@ -20,4 +20,5 @@ "use strict"; | ||
let RedisClusterService = class RedisClusterService { | ||
constructor(provider) { | ||
constructor(provider, options) { | ||
this.provider = provider; | ||
this.options = options; | ||
} | ||
@@ -36,2 +37,18 @@ getCluster(name) { | ||
} | ||
disconnectAllClients() { | ||
const closeConnection = ({ clusters, defaultKey }) => (options) => { | ||
const name = options.name || defaultKey; | ||
const cluster = clusters.get(name); | ||
if (cluster) { | ||
cluster.disconnect(); | ||
} | ||
}; | ||
const closeClusterConnection = closeConnection(this.provider); | ||
if (Array.isArray(this.options)) { | ||
this.options.forEach(closeClusterConnection); | ||
} | ||
else { | ||
closeClusterConnection(this.options); | ||
} | ||
} | ||
}; | ||
@@ -41,4 +58,5 @@ RedisClusterService = __decorate([ | ||
__param(0, common_1.Inject(cluster_constants_1.REDIS_CLUSTER)), | ||
__metadata("design:paramtypes", [Object]) | ||
__param(1, common_1.Inject(cluster_constants_1.REDIS_CLUSTER_MODULE_OPTIONS)), | ||
__metadata("design:paramtypes", [Object, Object]) | ||
], RedisClusterService); | ||
exports.RedisClusterService = RedisClusterService; |
@@ -48,3 +48,3 @@ "use strict"; | ||
const client = clients.get(name); | ||
if (client && !options.keepAlive) { | ||
if (client && !options.keepAlive && !options.disableDisconnectOnShutdown) { | ||
client.disconnect(); | ||
@@ -51,0 +51,0 @@ } |
@@ -7,2 +7,3 @@ import { ModuleMetadata } from '@nestjs/common/interfaces'; | ||
onClientReady?(client: Redis): Promise<void>; | ||
disableDisconnectOnShutdown?: boolean; | ||
} | ||
@@ -9,0 +10,0 @@ export interface RedisModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> { |
import * as IORedis from 'ioredis'; | ||
import { RedisClient } from './redis.provider'; | ||
import { RedisModuleOptions } from './redis.interface'; | ||
export declare class RedisService { | ||
private readonly redisClient; | ||
constructor(redisClient: RedisClient); | ||
private readonly options; | ||
constructor(redisClient: RedisClient, options: RedisModuleOptions | RedisModuleOptions[]); | ||
getClient(name?: string): IORedis.Redis; | ||
getClients(): Map<string, IORedis.Redis>; | ||
disconnectAllClients(): void; | ||
} |
@@ -20,4 +20,5 @@ "use strict"; | ||
let RedisService = class RedisService { | ||
constructor(redisClient) { | ||
constructor(redisClient, options) { | ||
this.redisClient = redisClient; | ||
this.options = options; | ||
} | ||
@@ -36,2 +37,18 @@ getClient(name) { | ||
} | ||
disconnectAllClients() { | ||
const closeConnection = ({ clients, defaultKey }) => (options) => { | ||
const name = options.name || defaultKey; | ||
const client = clients.get(name); | ||
if (client && !options.keepAlive) { | ||
client.disconnect(); | ||
} | ||
}; | ||
const closeClientConnection = closeConnection(this.redisClient); | ||
if (Array.isArray(this.options)) { | ||
this.options.forEach(closeClientConnection); | ||
} | ||
else { | ||
closeClientConnection(this.options); | ||
} | ||
} | ||
}; | ||
@@ -41,4 +58,5 @@ RedisService = __decorate([ | ||
__param(0, common_1.Inject(redis_constants_1.REDIS_CLIENT)), | ||
__metadata("design:paramtypes", [Object]) | ||
__param(1, common_1.Inject(redis_constants_1.REDIS_MODULE_OPTIONS)), | ||
__metadata("design:paramtypes", [Object, Object]) | ||
], RedisService); | ||
exports.RedisService = RedisService; |
{ | ||
"name": "nestjs-redis-cluster", | ||
"version": "2.0.8", | ||
"version": "2.1.0-experimental", | ||
"description": "A nestjs redis module w/ cluster support", | ||
@@ -15,3 +15,3 @@ "author": "Ishmael Samuel (useparagon.com)", | ||
"prepublish:npm": "yarn run build", | ||
"publish:npm": "yarn publish --access public", | ||
"publish:npm": "yarn publish --access public --tag=experimental", | ||
"test": "jest", | ||
@@ -18,0 +18,0 @@ "test:watch": "jest --watch", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43045
631
2