@voiceflow/nestjs-redis
Advanced tools
| import { Logger } from '@nestjs/common'; | ||
| export declare const logger: Logger; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.logger = void 0; | ||
| const common_1 = require("@nestjs/common"); | ||
| const cluster_constants_1 = require("./cluster.constants"); | ||
| exports.logger = new common_1.Logger(cluster_constants_1.CLUSTER_MODULE_ID, { timestamp: true }); |
| import type { Cluster } from 'ioredis'; | ||
| import { ClusterClients } from './interfaces'; | ||
| import { ClientNamespace } from '../interfaces'; | ||
| /** | ||
| * Manager for cluster clients. | ||
| * | ||
| * @public | ||
| */ | ||
| export declare class ClusterManager { | ||
| private readonly clusterClients; | ||
| constructor(clusterClients: ClusterClients); | ||
| /** | ||
| * Retrieves all cluster clients. | ||
| */ | ||
| get clients(): ReadonlyMap<ClientNamespace, Cluster>; | ||
| /** | ||
| * Retrieves a cluster client by namespace. | ||
| */ | ||
| getClient(namespace?: ClientNamespace): Cluster; | ||
| } |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.ClusterManager = void 0; | ||
| const tslib_1 = require("tslib"); | ||
| const common_1 = require("@nestjs/common"); | ||
| const cluster_constants_1 = require("./cluster.constants"); | ||
| const utils_1 = require("../utils"); | ||
| const errors_1 = require("../errors"); | ||
| /** | ||
| * Manager for cluster clients. | ||
| * | ||
| * @public | ||
| */ | ||
| let ClusterManager = class ClusterManager { | ||
| constructor(clusterClients) { | ||
| this.clusterClients = clusterClients; | ||
| } | ||
| /** | ||
| * Retrieves all cluster clients. | ||
| */ | ||
| get clients() { | ||
| return this.clusterClients; | ||
| } | ||
| /** | ||
| * Retrieves a cluster client by namespace. | ||
| */ | ||
| getClient(namespace = cluster_constants_1.DEFAULT_CLUSTER_NAMESPACE) { | ||
| const client = this.clusterClients.get(namespace); | ||
| if (!client) | ||
| throw new errors_1.ClientNotFoundError((0, utils_1.parseNamespace)(namespace), 'cluster'); | ||
| return client; | ||
| } | ||
| }; | ||
| ClusterManager = tslib_1.__decorate([ | ||
| (0, common_1.Injectable)(), | ||
| tslib_1.__param(0, (0, common_1.Inject)(cluster_constants_1.CLUSTER_CLIENTS)), | ||
| tslib_1.__metadata("design:paramtypes", [Object]) | ||
| ], ClusterManager); | ||
| exports.ClusterManager = ClusterManager; |
| export declare const CLUSTER_OPTIONS: unique symbol; | ||
| export declare const CLUSTER_MERGED_OPTIONS: unique symbol; | ||
| export declare const CLUSTER_CLIENTS: unique symbol; | ||
| export declare const DEFAULT_CLUSTER_NAMESPACE = "default"; | ||
| export declare const CLUSTER_MODULE_ID = "ClusterModule"; | ||
| export declare const NAMESPACE_KEY: unique symbol; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.NAMESPACE_KEY = exports.CLUSTER_MODULE_ID = exports.DEFAULT_CLUSTER_NAMESPACE = exports.CLUSTER_CLIENTS = exports.CLUSTER_MERGED_OPTIONS = exports.CLUSTER_OPTIONS = void 0; | ||
| exports.CLUSTER_OPTIONS = Symbol(); | ||
| exports.CLUSTER_MERGED_OPTIONS = Symbol(); | ||
| exports.CLUSTER_CLIENTS = Symbol(); | ||
| exports.DEFAULT_CLUSTER_NAMESPACE = 'default'; | ||
| exports.CLUSTER_MODULE_ID = 'ClusterModule'; | ||
| exports.NAMESPACE_KEY = Symbol(); |
| import { DynamicModule, OnApplicationShutdown } from '@nestjs/common'; | ||
| import { ModuleRef } from '@nestjs/core'; | ||
| import { ClusterModuleOptions, ClusterModuleAsyncOptions } from './interfaces'; | ||
| /** | ||
| * @public | ||
| */ | ||
| export declare class ClusterModule implements OnApplicationShutdown { | ||
| private moduleRef; | ||
| constructor(moduleRef: ModuleRef); | ||
| /** | ||
| * Registers the module synchronously. | ||
| */ | ||
| static forRoot(options: ClusterModuleOptions, isGlobal?: boolean): DynamicModule; | ||
| /** | ||
| * Registers the module asynchronously. | ||
| */ | ||
| static forRootAsync(options: ClusterModuleAsyncOptions, isGlobal?: boolean): DynamicModule; | ||
| onApplicationShutdown(): Promise<void>; | ||
| } |
| "use strict"; | ||
| var ClusterModule_1; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.ClusterModule = void 0; | ||
| const tslib_1 = require("tslib"); | ||
| const common_1 = require("@nestjs/common"); | ||
| const core_1 = require("@nestjs/core"); | ||
| const cluster_manager_1 = require("./cluster-manager"); | ||
| const cluster_providers_1 = require("./cluster.providers"); | ||
| const cluster_constants_1 = require("./cluster.constants"); | ||
| const common_2 = require("./common"); | ||
| const utils_1 = require("../utils"); | ||
| const cluster_logger_1 = require("./cluster-logger"); | ||
| const errors_1 = require("../errors"); | ||
| const messages_1 = require("../messages"); | ||
| /** | ||
| * @public | ||
| */ | ||
| let ClusterModule = ClusterModule_1 = class ClusterModule { | ||
| constructor(moduleRef) { | ||
| this.moduleRef = moduleRef; | ||
| } | ||
| /** | ||
| * Registers the module synchronously. | ||
| */ | ||
| static forRoot(options, isGlobal = true) { | ||
| const clusterClientProviders = (0, cluster_providers_1.createClusterClientProviders)(); | ||
| const providers = [ | ||
| (0, cluster_providers_1.createOptionsProvider)(options), | ||
| cluster_providers_1.clusterClientsProvider, | ||
| cluster_providers_1.mergedOptionsProvider, | ||
| cluster_manager_1.ClusterManager, | ||
| ...clusterClientProviders | ||
| ]; | ||
| return { | ||
| global: isGlobal, | ||
| module: ClusterModule_1, | ||
| providers, | ||
| exports: [cluster_manager_1.ClusterManager, ...clusterClientProviders] | ||
| }; | ||
| } | ||
| /** | ||
| * Registers the module asynchronously. | ||
| */ | ||
| static forRootAsync(options, isGlobal = true) { | ||
| var _a; | ||
| if (!options.useFactory && !options.useClass && !options.useExisting) { | ||
| throw new errors_1.MissingConfigurationsError(); | ||
| } | ||
| const clusterClientProviders = (0, cluster_providers_1.createClusterClientProviders)(); | ||
| const providers = [ | ||
| ...(0, cluster_providers_1.createAsyncProviders)(options), | ||
| cluster_providers_1.clusterClientsProvider, | ||
| cluster_providers_1.mergedOptionsProvider, | ||
| cluster_manager_1.ClusterManager, | ||
| ...clusterClientProviders, | ||
| ...((_a = options.extraProviders) !== null && _a !== void 0 ? _a : []) | ||
| ]; | ||
| return { | ||
| global: isGlobal, | ||
| module: ClusterModule_1, | ||
| imports: options.imports, | ||
| providers, | ||
| exports: [cluster_manager_1.ClusterManager, ...clusterClientProviders] | ||
| }; | ||
| } | ||
| async onApplicationShutdown() { | ||
| const { closeClient } = this.moduleRef.get(cluster_constants_1.CLUSTER_MERGED_OPTIONS, { strict: false }); | ||
| if (closeClient) { | ||
| const results = await (0, common_2.destroy)(this.moduleRef.get(cluster_constants_1.CLUSTER_CLIENTS, { strict: false })); | ||
| results.forEach(([namespace, quit]) => { | ||
| if ((0, utils_1.isResolution)(namespace) && (0, utils_1.isRejection)(quit) && (0, utils_1.isError)(quit.reason)) { | ||
| cluster_logger_1.logger.error((0, messages_1.ERROR_LOG)((0, utils_1.parseNamespace)(namespace.value), quit.reason.message), quit.reason.stack); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| }; | ||
| ClusterModule = ClusterModule_1 = tslib_1.__decorate([ | ||
| (0, common_1.Module)({}), | ||
| tslib_1.__metadata("design:paramtypes", [core_1.ModuleRef]) | ||
| ], ClusterModule); | ||
| exports.ClusterModule = ClusterModule; |
| import { Provider, FactoryProvider, ValueProvider } from '@nestjs/common'; | ||
| import type { Cluster } from 'ioredis'; | ||
| import { ClusterModuleOptions, ClusterModuleAsyncOptions, ClusterOptionsFactory, ClusterClients } from './interfaces'; | ||
| export declare const createOptionsProvider: (options: ClusterModuleOptions) => ValueProvider<ClusterModuleOptions>; | ||
| export declare const createAsyncProviders: (options: ClusterModuleAsyncOptions) => Provider[]; | ||
| export declare const createAsyncOptions: (optionsFactory: ClusterOptionsFactory) => Promise<ClusterModuleOptions>; | ||
| export declare const createAsyncOptionsProvider: (options: ClusterModuleAsyncOptions) => Provider; | ||
| export declare const createClusterClientProviders: () => FactoryProvider<Cluster>[]; | ||
| export declare const clusterClientsProvider: FactoryProvider<ClusterClients>; | ||
| export declare const mergedOptionsProvider: FactoryProvider<ClusterModuleOptions>; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.mergedOptionsProvider = exports.clusterClientsProvider = exports.createClusterClientProviders = exports.createAsyncOptionsProvider = exports.createAsyncOptions = exports.createAsyncProviders = exports.createOptionsProvider = void 0; | ||
| const cluster_constants_1 = require("./cluster.constants"); | ||
| const common_1 = require("./common"); | ||
| const cluster_manager_1 = require("./cluster-manager"); | ||
| const default_options_1 = require("./default-options"); | ||
| const createOptionsProvider = (options) => ({ | ||
| provide: cluster_constants_1.CLUSTER_OPTIONS, | ||
| useValue: options | ||
| }); | ||
| exports.createOptionsProvider = createOptionsProvider; | ||
| const createAsyncProviders = (options) => { | ||
| if (options.useClass) { | ||
| return [ | ||
| { | ||
| provide: options.useClass, | ||
| useClass: options.useClass | ||
| }, | ||
| (0, exports.createAsyncOptionsProvider)(options) | ||
| ]; | ||
| } | ||
| if (options.useExisting || options.useFactory) | ||
| return [(0, exports.createAsyncOptionsProvider)(options)]; | ||
| return []; | ||
| }; | ||
| exports.createAsyncProviders = createAsyncProviders; | ||
| const createAsyncOptions = async (optionsFactory) => { | ||
| return await optionsFactory.createClusterOptions(); | ||
| }; | ||
| exports.createAsyncOptions = createAsyncOptions; | ||
| const createAsyncOptionsProvider = (options) => { | ||
| if (options.useFactory) { | ||
| return { | ||
| provide: cluster_constants_1.CLUSTER_OPTIONS, | ||
| useFactory: options.useFactory, | ||
| inject: options.inject | ||
| }; | ||
| } | ||
| if (options.useClass) { | ||
| return { | ||
| provide: cluster_constants_1.CLUSTER_OPTIONS, | ||
| useFactory: exports.createAsyncOptions, | ||
| inject: [options.useClass] | ||
| }; | ||
| } | ||
| if (options.useExisting) { | ||
| return { | ||
| provide: cluster_constants_1.CLUSTER_OPTIONS, | ||
| useFactory: exports.createAsyncOptions, | ||
| inject: [options.useExisting] | ||
| }; | ||
| } | ||
| return { | ||
| provide: cluster_constants_1.CLUSTER_OPTIONS, | ||
| useValue: {} | ||
| }; | ||
| }; | ||
| exports.createAsyncOptionsProvider = createAsyncOptionsProvider; | ||
| const createClusterClientProviders = () => { | ||
| const providers = []; | ||
| common_1.namespaces.forEach((token, namespace) => { | ||
| providers.push({ | ||
| provide: token, | ||
| useFactory: (clusterManager) => clusterManager.getClient(namespace), | ||
| inject: [cluster_manager_1.ClusterManager] | ||
| }); | ||
| }); | ||
| return providers; | ||
| }; | ||
| exports.createClusterClientProviders = createClusterClientProviders; | ||
| exports.clusterClientsProvider = { | ||
| provide: cluster_constants_1.CLUSTER_CLIENTS, | ||
| useFactory: (options) => { | ||
| var _a; | ||
| const clients = new Map(); | ||
| if (Array.isArray(options.config)) { | ||
| options.config.forEach(item => { | ||
| var _a; | ||
| return clients.set((_a = item.namespace) !== null && _a !== void 0 ? _a : cluster_constants_1.DEFAULT_CLUSTER_NAMESPACE, (0, common_1.createClient)(item, { readyLog: options.readyLog, errorLog: options.errorLog })); | ||
| }); | ||
| } | ||
| else if (options.config) { | ||
| clients.set((_a = options.config.namespace) !== null && _a !== void 0 ? _a : cluster_constants_1.DEFAULT_CLUSTER_NAMESPACE, (0, common_1.createClient)(options.config, { readyLog: options.readyLog, errorLog: options.errorLog })); | ||
| } | ||
| return clients; | ||
| }, | ||
| inject: [cluster_constants_1.CLUSTER_MERGED_OPTIONS] | ||
| }; | ||
| exports.mergedOptionsProvider = { | ||
| provide: cluster_constants_1.CLUSTER_MERGED_OPTIONS, | ||
| useFactory: (options) => (Object.assign(Object.assign({}, default_options_1.defaultClusterModuleOptions), options)), | ||
| inject: [cluster_constants_1.CLUSTER_OPTIONS] | ||
| }; |
| import { ClientNamespace } from '../../interfaces'; | ||
| export declare const namespaces: Map<ClientNamespace, ClientNamespace>; | ||
| /** | ||
| * This decorator is used to mark a specific constructor parameter as a cluster client. | ||
| * | ||
| * @param namespace - Client name | ||
| * | ||
| * @public | ||
| */ | ||
| export declare const InjectCluster: (namespace?: ClientNamespace) => ParameterDecorator; | ||
| /** | ||
| * This function generates an injection token for a cluster client. | ||
| * | ||
| * @param namespace - Client name | ||
| * | ||
| * @public | ||
| */ | ||
| export declare const getClusterToken: (namespace: ClientNamespace) => ClientNamespace; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.getClusterToken = exports.InjectCluster = exports.namespaces = void 0; | ||
| const common_1 = require("@nestjs/common"); | ||
| const cluster_constants_1 = require("../cluster.constants"); | ||
| const utils_1 = require("../../utils"); | ||
| exports.namespaces = new Map(); | ||
| /** | ||
| * This decorator is used to mark a specific constructor parameter as a cluster client. | ||
| * | ||
| * @param namespace - Client name | ||
| * | ||
| * @public | ||
| */ | ||
| const InjectCluster = (namespace = cluster_constants_1.DEFAULT_CLUSTER_NAMESPACE) => { | ||
| const token = (0, exports.getClusterToken)(namespace); | ||
| exports.namespaces.set(namespace, token); | ||
| return (0, common_1.Inject)(token); | ||
| }; | ||
| exports.InjectCluster = InjectCluster; | ||
| /** | ||
| * This function generates an injection token for a cluster client. | ||
| * | ||
| * @param namespace - Client name | ||
| * | ||
| * @public | ||
| */ | ||
| const getClusterToken = (namespace) => { | ||
| if ((0, utils_1.isSymbol)(namespace)) | ||
| return namespace; | ||
| return `${cluster_constants_1.CLUSTER_MODULE_ID}:${namespace}`; | ||
| }; | ||
| exports.getClusterToken = getClusterToken; |
| import { Cluster } from 'ioredis'; | ||
| import { ClusterClientOptions, ClusterClients, ClusterModuleOptions } from '../interfaces'; | ||
| import { ClientNamespace } from '../../interfaces'; | ||
| export declare const addListeners: ({ namespace, instance, readyLog, errorLog }: { | ||
| namespace: ClientNamespace; | ||
| instance: Cluster; | ||
| readyLog?: boolean | undefined; | ||
| errorLog?: boolean | undefined; | ||
| }) => void; | ||
| export declare const createClient: ({ namespace, nodes, onClientCreated, ...clusterOptions }: ClusterClientOptions, { readyLog, errorLog }: Partial<ClusterModuleOptions>) => Cluster; | ||
| export declare const destroy: (clients: ClusterClients) => Promise<[PromiseSettledResult<ClientNamespace>, PromiseSettledResult<"OK">][]>; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.destroy = exports.createClient = exports.addListeners = void 0; | ||
| const tslib_1 = require("tslib"); | ||
| const ioredis_1 = require("ioredis"); | ||
| const messages_1 = require("../../messages"); | ||
| const cluster_logger_1 = require("../cluster-logger"); | ||
| const utils_1 = require("../../utils"); | ||
| const constants_1 = require("../../constants"); | ||
| const cluster_constants_1 = require("../cluster.constants"); | ||
| const addListeners = ({ namespace, instance, readyLog, errorLog }) => { | ||
| Reflect.set(instance, cluster_constants_1.NAMESPACE_KEY, namespace); | ||
| if (readyLog) { | ||
| instance.on(constants_1.READY_EVENT, function () { | ||
| cluster_logger_1.logger.log((0, messages_1.READY_LOG)((0, utils_1.parseNamespace)(Reflect.get(this, cluster_constants_1.NAMESPACE_KEY)))); | ||
| }); | ||
| } | ||
| if (errorLog) { | ||
| instance.on(constants_1.ERROR_EVENT, function (error) { | ||
| cluster_logger_1.logger.error((0, messages_1.ERROR_LOG)((0, utils_1.parseNamespace)(Reflect.get(this, cluster_constants_1.NAMESPACE_KEY)), error.message), error.stack); | ||
| }); | ||
| } | ||
| }; | ||
| exports.addListeners = addListeners; | ||
| const createClient = (_a, _b) => { | ||
| var { namespace, nodes, onClientCreated } = _a, clusterOptions = tslib_1.__rest(_a, ["namespace", "nodes", "onClientCreated"]); | ||
| var readyLog = _b.readyLog, errorLog = _b.errorLog; | ||
| const client = new ioredis_1.Cluster(nodes, clusterOptions); | ||
| (0, exports.addListeners)({ namespace: namespace !== null && namespace !== void 0 ? namespace : cluster_constants_1.DEFAULT_CLUSTER_NAMESPACE, instance: client, readyLog, errorLog }); | ||
| if (onClientCreated) | ||
| onClientCreated(client); | ||
| return client; | ||
| }; | ||
| exports.createClient = createClient; | ||
| const destroy = async (clients) => { | ||
| const promises = []; | ||
| clients.forEach((client, namespace) => { | ||
| if (client.status === constants_1.END_EVENT) | ||
| return; | ||
| if (client.status === constants_1.READY_EVENT) { | ||
| promises.push(Promise.allSettled([namespace, client.quit()])); | ||
| return; | ||
| } | ||
| client.disconnect(); | ||
| }); | ||
| return await Promise.all(promises); | ||
| }; | ||
| exports.destroy = destroy; |
| export * from './cluster.utils'; | ||
| export * from './cluster.decorator'; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const tslib_1 = require("tslib"); | ||
| tslib_1.__exportStar(require("./cluster.utils"), exports); | ||
| tslib_1.__exportStar(require("./cluster.decorator"), exports); |
| import { ClusterModuleOptions } from './interfaces'; | ||
| export declare const defaultClusterModuleOptions: Partial<ClusterModuleOptions>; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.defaultClusterModuleOptions = void 0; | ||
| exports.defaultClusterModuleOptions = { | ||
| closeClient: true, | ||
| readyLog: false, | ||
| errorLog: true, | ||
| config: undefined | ||
| }; |
| import { Type, ModuleMetadata, Provider } from '@nestjs/common'; | ||
| import type { Cluster } from 'ioredis'; | ||
| import { ClusterNode, ClusterOptions } from 'ioredis'; | ||
| import { ClientNamespace } from '../../interfaces'; | ||
| /** | ||
| * @public | ||
| */ | ||
| export interface ClusterClientOptions extends ClusterOptions { | ||
| /** | ||
| * Client name. If client name is not given then it will be called "default". | ||
| * Different clients must have different names. | ||
| * | ||
| * @defaultValue `"default"` | ||
| */ | ||
| namespace?: ClientNamespace; | ||
| /** | ||
| * List of cluster nodes. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * // Connect with url | ||
| * ['redis://:authpassword@127.0.0.1:16380'] | ||
| * ``` | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * // Connect with host, port | ||
| * [{ host: '127.0.0.1', port: 16380 }] | ||
| * ``` | ||
| */ | ||
| nodes: ClusterNode[]; | ||
| /** | ||
| * Function to be executed as soon as the client is created. | ||
| * | ||
| * @param client - The new client created | ||
| */ | ||
| onClientCreated?: (client: Cluster) => void; | ||
| } | ||
| /** | ||
| * @public | ||
| */ | ||
| export interface ClusterModuleOptions { | ||
| /** | ||
| * If set to `true`, all clients will be closed automatically on nestjs application shutdown. | ||
| * | ||
| * @defaultValue `true` | ||
| */ | ||
| closeClient?: boolean; | ||
| /** | ||
| * If set to `true`, then ready logging will be displayed when the client is ready. | ||
| * | ||
| * @defaultValue `false` | ||
| */ | ||
| readyLog?: boolean; | ||
| /** | ||
| * If set to `true`, then errors that occurred while connecting will be displayed by the built-in logger. | ||
| * | ||
| * @defaultValue `true` | ||
| */ | ||
| errorLog?: boolean; | ||
| /** | ||
| * Used to specify single or multiple clients. | ||
| */ | ||
| config: ClusterClientOptions | ClusterClientOptions[]; | ||
| } | ||
| /** | ||
| * @public | ||
| */ | ||
| export interface ClusterModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> { | ||
| useFactory?: (...args: any[]) => ClusterModuleOptions | Promise<ClusterModuleOptions>; | ||
| useClass?: Type<ClusterOptionsFactory>; | ||
| useExisting?: Type<ClusterOptionsFactory>; | ||
| inject?: any[]; | ||
| extraProviders?: Provider[]; | ||
| } | ||
| /** | ||
| * @public | ||
| */ | ||
| export interface ClusterOptionsFactory { | ||
| createClusterOptions: () => ClusterModuleOptions | Promise<ClusterModuleOptions>; | ||
| } |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); |
| import type { Cluster } from 'ioredis'; | ||
| import { ClientNamespace } from '../../interfaces'; | ||
| export * from './cluster-module-options.interface'; | ||
| export type ClusterClients = Map<ClientNamespace, Cluster>; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const tslib_1 = require("tslib"); | ||
| tslib_1.__exportStar(require("./cluster-module-options.interface"), exports); |
| export declare const ERROR_EVENT = "error"; | ||
| export declare const READY_EVENT = "ready"; | ||
| export declare const END_EVENT = "end"; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.END_EVENT = exports.READY_EVENT = exports.ERROR_EVENT = void 0; | ||
| exports.ERROR_EVENT = 'error'; | ||
| exports.READY_EVENT = 'ready'; | ||
| exports.END_EVENT = 'end'; |
| import { ClientType } from '../interfaces'; | ||
| /** | ||
| * Thrown when consumer tries to get client that does not exist. | ||
| */ | ||
| export declare class ClientNotFoundError extends Error { | ||
| constructor(namespace: string, type: ClientType); | ||
| } |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.ClientNotFoundError = void 0; | ||
| /** | ||
| * Thrown when consumer tries to get client that does not exist. | ||
| */ | ||
| class ClientNotFoundError extends Error { | ||
| constructor(namespace, type) { | ||
| super(`The ${type === 'redis' ? 'redis' : 'cluster'} client "${namespace}" could not be found in the application context.`); | ||
| this.name = ClientNotFoundError.name; | ||
| Error.captureStackTrace(this, this.constructor); | ||
| } | ||
| } | ||
| exports.ClientNotFoundError = ClientNotFoundError; |
| export * from './missing-configurations.error'; | ||
| export * from './client-not-found.error'; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const tslib_1 = require("tslib"); | ||
| tslib_1.__exportStar(require("./missing-configurations.error"), exports); | ||
| tslib_1.__exportStar(require("./client-not-found.error"), exports); |
| /** | ||
| * Thrown when async configurations are missing. | ||
| */ | ||
| export declare class MissingConfigurationsError extends Error { | ||
| constructor(); | ||
| } |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.MissingConfigurationsError = void 0; | ||
| /** | ||
| * Thrown when async configurations are missing. | ||
| */ | ||
| class MissingConfigurationsError extends Error { | ||
| constructor() { | ||
| super(`The asynchronous configurations are missing. Expected one of: "useFactory", "useClass", "useExisting".`); | ||
| this.name = MissingConfigurationsError.name; | ||
| Error.captureStackTrace(this, this.constructor); | ||
| } | ||
| } | ||
| exports.MissingConfigurationsError = MissingConfigurationsError; |
| export { RedisModule } from './redis/redis.module'; | ||
| export { DEFAULT_REDIS_NAMESPACE } from './redis/redis.constants'; | ||
| export { RedisManager, RedisManager as RedisService } from './redis/redis-manager'; | ||
| export { InjectRedis, getRedisToken } from './redis/common'; | ||
| export { ClusterModule } from './cluster/cluster.module'; | ||
| export { DEFAULT_CLUSTER_NAMESPACE } from './cluster/cluster.constants'; | ||
| export { ClusterManager, ClusterManager as ClusterService } from './cluster/cluster-manager'; | ||
| export { InjectCluster, getClusterToken } from './cluster/common'; | ||
| export { ClientNamespace } from './interfaces'; | ||
| export { RedisModuleOptions, RedisModuleAsyncOptions, RedisOptionsFactory, RedisClientOptions } from './redis/interfaces'; | ||
| export { ClusterModuleOptions, ClusterModuleAsyncOptions, ClusterOptionsFactory, ClusterClientOptions } from './cluster/interfaces'; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.getClusterToken = exports.InjectCluster = exports.ClusterService = exports.ClusterManager = exports.DEFAULT_CLUSTER_NAMESPACE = exports.ClusterModule = exports.getRedisToken = exports.InjectRedis = exports.RedisService = exports.RedisManager = exports.DEFAULT_REDIS_NAMESPACE = exports.RedisModule = void 0; | ||
| var redis_module_1 = require("./redis/redis.module"); | ||
| Object.defineProperty(exports, "RedisModule", { enumerable: true, get: function () { return redis_module_1.RedisModule; } }); | ||
| var redis_constants_1 = require("./redis/redis.constants"); | ||
| Object.defineProperty(exports, "DEFAULT_REDIS_NAMESPACE", { enumerable: true, get: function () { return redis_constants_1.DEFAULT_REDIS_NAMESPACE; } }); | ||
| var redis_manager_1 = require("./redis/redis-manager"); | ||
| Object.defineProperty(exports, "RedisManager", { enumerable: true, get: function () { return redis_manager_1.RedisManager; } }); | ||
| Object.defineProperty(exports, "RedisService", { enumerable: true, get: function () { return redis_manager_1.RedisManager; } }); | ||
| var common_1 = require("./redis/common"); | ||
| Object.defineProperty(exports, "InjectRedis", { enumerable: true, get: function () { return common_1.InjectRedis; } }); | ||
| Object.defineProperty(exports, "getRedisToken", { enumerable: true, get: function () { return common_1.getRedisToken; } }); | ||
| var cluster_module_1 = require("./cluster/cluster.module"); | ||
| Object.defineProperty(exports, "ClusterModule", { enumerable: true, get: function () { return cluster_module_1.ClusterModule; } }); | ||
| var cluster_constants_1 = require("./cluster/cluster.constants"); | ||
| Object.defineProperty(exports, "DEFAULT_CLUSTER_NAMESPACE", { enumerable: true, get: function () { return cluster_constants_1.DEFAULT_CLUSTER_NAMESPACE; } }); | ||
| var cluster_manager_1 = require("./cluster/cluster-manager"); | ||
| Object.defineProperty(exports, "ClusterManager", { enumerable: true, get: function () { return cluster_manager_1.ClusterManager; } }); | ||
| Object.defineProperty(exports, "ClusterService", { enumerable: true, get: function () { return cluster_manager_1.ClusterManager; } }); | ||
| var common_2 = require("./cluster/common"); | ||
| Object.defineProperty(exports, "InjectCluster", { enumerable: true, get: function () { return common_2.InjectCluster; } }); | ||
| Object.defineProperty(exports, "getClusterToken", { enumerable: true, get: function () { return common_2.getClusterToken; } }); |
| export type ClientNamespace = string | symbol; | ||
| export type ClientType = 'redis' | 'cluster'; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); |
| export declare const READY_LOG: (namespace: string) => string; | ||
| export declare const ERROR_LOG: (namespace: string, message: string) => string; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.ERROR_LOG = exports.READY_LOG = void 0; | ||
| const READY_LOG = (namespace) => `${namespace}: connected successfully to the server`; | ||
| exports.READY_LOG = READY_LOG; | ||
| const ERROR_LOG = (namespace, message) => `${namespace}: ${message}`; | ||
| exports.ERROR_LOG = ERROR_LOG; |
| export * from './redis.utils'; | ||
| export * from './redis.decorator'; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const tslib_1 = require("tslib"); | ||
| tslib_1.__exportStar(require("./redis.utils"), exports); | ||
| tslib_1.__exportStar(require("./redis.decorator"), exports); |
| import { ClientNamespace } from '../../interfaces'; | ||
| export declare const namespaces: Map<ClientNamespace, ClientNamespace>; | ||
| /** | ||
| * This decorator is used to mark a specific constructor parameter as a redis client. | ||
| * | ||
| * @param namespace - Client name | ||
| * | ||
| * @public | ||
| */ | ||
| export declare const InjectRedis: (namespace?: ClientNamespace) => ParameterDecorator; | ||
| /** | ||
| * This function generates an injection token for a redis client. | ||
| * | ||
| * @param namespace - Client name | ||
| * | ||
| * @public | ||
| */ | ||
| export declare const getRedisToken: (namespace: ClientNamespace) => ClientNamespace; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.getRedisToken = exports.InjectRedis = exports.namespaces = void 0; | ||
| const common_1 = require("@nestjs/common"); | ||
| const redis_constants_1 = require("../redis.constants"); | ||
| const utils_1 = require("../../utils"); | ||
| exports.namespaces = new Map(); | ||
| /** | ||
| * This decorator is used to mark a specific constructor parameter as a redis client. | ||
| * | ||
| * @param namespace - Client name | ||
| * | ||
| * @public | ||
| */ | ||
| const InjectRedis = (namespace = redis_constants_1.DEFAULT_REDIS_NAMESPACE) => { | ||
| const token = (0, exports.getRedisToken)(namespace); | ||
| exports.namespaces.set(namespace, token); | ||
| return (0, common_1.Inject)(token); | ||
| }; | ||
| exports.InjectRedis = InjectRedis; | ||
| /** | ||
| * This function generates an injection token for a redis client. | ||
| * | ||
| * @param namespace - Client name | ||
| * | ||
| * @public | ||
| */ | ||
| const getRedisToken = (namespace) => { | ||
| if ((0, utils_1.isSymbol)(namespace)) | ||
| return namespace; | ||
| return `${redis_constants_1.REDIS_MODULE_ID}:${namespace}`; | ||
| }; | ||
| exports.getRedisToken = getRedisToken; |
| import Redis from 'ioredis'; | ||
| import { RedisClientOptions, RedisClients, RedisModuleOptions } from '../interfaces'; | ||
| import { ClientNamespace } from '../../interfaces'; | ||
| export declare const addListeners: ({ namespace, instance, readyLog, errorLog }: { | ||
| namespace: ClientNamespace; | ||
| instance: Redis; | ||
| readyLog?: boolean | undefined; | ||
| errorLog?: boolean | undefined; | ||
| }) => void; | ||
| export declare const createClient: ({ namespace, url, path, onClientCreated, ...redisOptions }: RedisClientOptions, { readyLog, errorLog }: RedisModuleOptions) => Redis; | ||
| export declare const destroy: (clients: RedisClients) => Promise<[PromiseSettledResult<ClientNamespace>, PromiseSettledResult<"OK">][]>; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.destroy = exports.createClient = exports.addListeners = void 0; | ||
| const tslib_1 = require("tslib"); | ||
| const ioredis_1 = tslib_1.__importDefault(require("ioredis")); | ||
| const messages_1 = require("../../messages"); | ||
| const redis_logger_1 = require("../redis-logger"); | ||
| const utils_1 = require("../../utils"); | ||
| const constants_1 = require("../../constants"); | ||
| const redis_constants_1 = require("../redis.constants"); | ||
| const addListeners = ({ namespace, instance, readyLog, errorLog }) => { | ||
| Reflect.set(instance, redis_constants_1.NAMESPACE_KEY, namespace); | ||
| if (readyLog) { | ||
| instance.on(constants_1.READY_EVENT, function () { | ||
| redis_logger_1.logger.log((0, messages_1.READY_LOG)((0, utils_1.parseNamespace)(Reflect.get(this, redis_constants_1.NAMESPACE_KEY)))); | ||
| }); | ||
| } | ||
| if (errorLog) { | ||
| instance.on(constants_1.ERROR_EVENT, function (error) { | ||
| redis_logger_1.logger.error((0, messages_1.ERROR_LOG)((0, utils_1.parseNamespace)(Reflect.get(this, redis_constants_1.NAMESPACE_KEY)), error.message), error.stack); | ||
| }); | ||
| } | ||
| }; | ||
| exports.addListeners = addListeners; | ||
| const createClient = (_a, _b) => { | ||
| var { namespace, url, path, onClientCreated } = _a, redisOptions = tslib_1.__rest(_a, ["namespace", "url", "path", "onClientCreated"]); | ||
| var readyLog = _b.readyLog, errorLog = _b.errorLog; | ||
| let client; | ||
| if (url) | ||
| client = new ioredis_1.default(url, redisOptions); | ||
| else if (path) | ||
| client = new ioredis_1.default(path, redisOptions); | ||
| else | ||
| client = new ioredis_1.default(redisOptions); | ||
| (0, exports.addListeners)({ namespace: namespace !== null && namespace !== void 0 ? namespace : redis_constants_1.DEFAULT_REDIS_NAMESPACE, instance: client, readyLog, errorLog }); | ||
| if (onClientCreated) | ||
| onClientCreated(client); | ||
| return client; | ||
| }; | ||
| exports.createClient = createClient; | ||
| const destroy = async (clients) => { | ||
| const promises = []; | ||
| clients.forEach((client, namespace) => { | ||
| if (client.status === constants_1.END_EVENT) | ||
| return; | ||
| if (client.status === constants_1.READY_EVENT) { | ||
| promises.push(Promise.allSettled([namespace, client.quit()])); | ||
| return; | ||
| } | ||
| client.disconnect(); | ||
| }); | ||
| return await Promise.all(promises); | ||
| }; | ||
| exports.destroy = destroy; |
| import { RedisModuleOptions } from './interfaces'; | ||
| export declare const defaultRedisModuleOptions: RedisModuleOptions; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.defaultRedisModuleOptions = void 0; | ||
| exports.defaultRedisModuleOptions = { | ||
| closeClient: true, | ||
| commonOptions: undefined, | ||
| readyLog: false, | ||
| errorLog: true, | ||
| config: undefined | ||
| }; |
| import { Redis } from 'ioredis'; | ||
| import { ClientNamespace } from '../../interfaces'; | ||
| export * from './redis-module-options.interface'; | ||
| export type RedisClients = Map<ClientNamespace, Redis>; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const tslib_1 = require("tslib"); | ||
| tslib_1.__exportStar(require("./redis-module-options.interface"), exports); |
| import { Type, ModuleMetadata, Provider } from '@nestjs/common'; | ||
| import { Redis, RedisOptions } from 'ioredis'; | ||
| import { ClientNamespace } from '../../interfaces'; | ||
| /** | ||
| * @public | ||
| */ | ||
| export interface RedisClientOptions extends RedisOptions { | ||
| /** | ||
| * Client name. If client name is not given then it will be called "default". | ||
| * Different clients must have different names. | ||
| * | ||
| * @defaultValue `"default"` | ||
| */ | ||
| namespace?: ClientNamespace; | ||
| /** | ||
| * URI scheme to be used to specify connection options as a redis:// URL or rediss:// URL. | ||
| * | ||
| * - redis - https://www.iana.org/assignments/uri-schemes/prov/redis | ||
| * - rediss - https://www.iana.org/assignments/uri-schemes/prov/rediss | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * // Connect to 127.0.0.1:6380, db 4, using password "authpassword": | ||
| * 'redis://:authpassword@127.0.0.1:6380/4' | ||
| * ``` | ||
| */ | ||
| url?: string; | ||
| /** | ||
| * Path to be used for Unix domain sockets. | ||
| */ | ||
| path?: string; | ||
| /** | ||
| * Function to be executed as soon as the client is created. | ||
| * | ||
| * @param client - The new client created | ||
| */ | ||
| onClientCreated?: (client: Redis) => void; | ||
| } | ||
| /** | ||
| * @public | ||
| */ | ||
| export interface RedisModuleOptions { | ||
| /** | ||
| * If set to `true`, all clients will be closed automatically on nestjs application shutdown. | ||
| * | ||
| * @defaultValue `true` | ||
| */ | ||
| closeClient?: boolean; | ||
| /** | ||
| * Common options to be passed to each client. | ||
| */ | ||
| commonOptions?: RedisOptions; | ||
| /** | ||
| * If set to `true`, then ready logging will be displayed when the client is ready. | ||
| * | ||
| * @defaultValue `false` | ||
| */ | ||
| readyLog?: boolean; | ||
| /** | ||
| * If set to `true`, then errors that occurred while connecting will be displayed by the built-in logger. | ||
| * | ||
| * @defaultValue `true` | ||
| */ | ||
| errorLog?: boolean; | ||
| /** | ||
| * Used to specify single or multiple clients. | ||
| */ | ||
| config?: RedisClientOptions | RedisClientOptions[]; | ||
| } | ||
| /** | ||
| * @public | ||
| */ | ||
| export interface RedisModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> { | ||
| useFactory?: (...args: any[]) => RedisModuleOptions | Promise<RedisModuleOptions>; | ||
| useClass?: Type<RedisOptionsFactory>; | ||
| useExisting?: Type<RedisOptionsFactory>; | ||
| inject?: any[]; | ||
| extraProviders?: Provider[]; | ||
| } | ||
| /** | ||
| * @public | ||
| */ | ||
| export interface RedisOptionsFactory { | ||
| createRedisOptions: () => RedisModuleOptions | Promise<RedisModuleOptions>; | ||
| } |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); |
| import { Logger } from '@nestjs/common'; | ||
| export declare const logger: Logger; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.logger = void 0; | ||
| const common_1 = require("@nestjs/common"); | ||
| const redis_constants_1 = require("./redis.constants"); | ||
| exports.logger = new common_1.Logger(redis_constants_1.REDIS_MODULE_ID, { timestamp: true }); |
| import { Redis } from 'ioredis'; | ||
| import { RedisClients } from './interfaces'; | ||
| import { ClientNamespace } from '../interfaces'; | ||
| /** | ||
| * Manager for redis clients. | ||
| * | ||
| * @public | ||
| */ | ||
| export declare class RedisManager { | ||
| private readonly redisClients; | ||
| constructor(redisClients: RedisClients); | ||
| /** | ||
| * Retrieves all redis clients. | ||
| */ | ||
| get clients(): ReadonlyMap<ClientNamespace, Redis>; | ||
| /** | ||
| * Retrieves a redis client by namespace. | ||
| */ | ||
| getClient(namespace?: ClientNamespace): Redis; | ||
| } |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.RedisManager = void 0; | ||
| const tslib_1 = require("tslib"); | ||
| const common_1 = require("@nestjs/common"); | ||
| const redis_constants_1 = require("./redis.constants"); | ||
| const utils_1 = require("../utils"); | ||
| const errors_1 = require("../errors"); | ||
| /** | ||
| * Manager for redis clients. | ||
| * | ||
| * @public | ||
| */ | ||
| let RedisManager = class RedisManager { | ||
| constructor(redisClients) { | ||
| this.redisClients = redisClients; | ||
| } | ||
| /** | ||
| * Retrieves all redis clients. | ||
| */ | ||
| get clients() { | ||
| return this.redisClients; | ||
| } | ||
| /** | ||
| * Retrieves a redis client by namespace. | ||
| */ | ||
| getClient(namespace = redis_constants_1.DEFAULT_REDIS_NAMESPACE) { | ||
| const client = this.redisClients.get(namespace); | ||
| if (!client) | ||
| throw new errors_1.ClientNotFoundError((0, utils_1.parseNamespace)(namespace), 'redis'); | ||
| return client; | ||
| } | ||
| }; | ||
| RedisManager = tslib_1.__decorate([ | ||
| (0, common_1.Injectable)(), | ||
| tslib_1.__param(0, (0, common_1.Inject)(redis_constants_1.REDIS_CLIENTS)), | ||
| tslib_1.__metadata("design:paramtypes", [Object]) | ||
| ], RedisManager); | ||
| exports.RedisManager = RedisManager; |
| export declare const REDIS_OPTIONS: unique symbol; | ||
| export declare const REDIS_MERGED_OPTIONS: unique symbol; | ||
| export declare const REDIS_CLIENTS: unique symbol; | ||
| export declare const DEFAULT_REDIS_NAMESPACE = "default"; | ||
| export declare const REDIS_MODULE_ID = "RedisModule"; | ||
| export declare const NAMESPACE_KEY: unique symbol; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.NAMESPACE_KEY = exports.REDIS_MODULE_ID = exports.DEFAULT_REDIS_NAMESPACE = exports.REDIS_CLIENTS = exports.REDIS_MERGED_OPTIONS = exports.REDIS_OPTIONS = void 0; | ||
| exports.REDIS_OPTIONS = Symbol(); | ||
| exports.REDIS_MERGED_OPTIONS = Symbol(); | ||
| exports.REDIS_CLIENTS = Symbol(); | ||
| exports.DEFAULT_REDIS_NAMESPACE = 'default'; | ||
| exports.REDIS_MODULE_ID = 'RedisModule'; | ||
| exports.NAMESPACE_KEY = Symbol(); |
| import { DynamicModule, OnApplicationShutdown } from '@nestjs/common'; | ||
| import { ModuleRef } from '@nestjs/core'; | ||
| import { RedisModuleOptions, RedisModuleAsyncOptions } from './interfaces'; | ||
| /** | ||
| * @public | ||
| */ | ||
| export declare class RedisModule implements OnApplicationShutdown { | ||
| private moduleRef; | ||
| constructor(moduleRef: ModuleRef); | ||
| /** | ||
| * Registers the module synchronously. | ||
| */ | ||
| static forRoot(options?: RedisModuleOptions, isGlobal?: boolean): DynamicModule; | ||
| /** | ||
| * Registers the module asynchronously. | ||
| */ | ||
| static forRootAsync(options: RedisModuleAsyncOptions, isGlobal?: boolean): DynamicModule; | ||
| onApplicationShutdown(): Promise<void>; | ||
| } |
| "use strict"; | ||
| var RedisModule_1; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.RedisModule = void 0; | ||
| const tslib_1 = require("tslib"); | ||
| const common_1 = require("@nestjs/common"); | ||
| const core_1 = require("@nestjs/core"); | ||
| const redis_manager_1 = require("./redis-manager"); | ||
| const redis_providers_1 = require("./redis.providers"); | ||
| const redis_constants_1 = require("./redis.constants"); | ||
| const common_2 = require("./common"); | ||
| const utils_1 = require("../utils"); | ||
| const redis_logger_1 = require("./redis-logger"); | ||
| const errors_1 = require("../errors"); | ||
| const messages_1 = require("../messages"); | ||
| /** | ||
| * @public | ||
| */ | ||
| let RedisModule = RedisModule_1 = class RedisModule { | ||
| constructor(moduleRef) { | ||
| this.moduleRef = moduleRef; | ||
| } | ||
| /** | ||
| * Registers the module synchronously. | ||
| */ | ||
| static forRoot(options = {}, isGlobal = true) { | ||
| const redisClientProviders = (0, redis_providers_1.createRedisClientProviders)(); | ||
| const providers = [ | ||
| (0, redis_providers_1.createOptionsProvider)(options), | ||
| redis_providers_1.redisClientsProvider, | ||
| redis_providers_1.mergedOptionsProvider, | ||
| redis_manager_1.RedisManager, | ||
| ...redisClientProviders | ||
| ]; | ||
| return { | ||
| global: isGlobal, | ||
| module: RedisModule_1, | ||
| providers, | ||
| exports: [redis_manager_1.RedisManager, ...redisClientProviders] | ||
| }; | ||
| } | ||
| /** | ||
| * Registers the module asynchronously. | ||
| */ | ||
| static forRootAsync(options, isGlobal = true) { | ||
| var _a; | ||
| if (!options.useFactory && !options.useClass && !options.useExisting) { | ||
| throw new errors_1.MissingConfigurationsError(); | ||
| } | ||
| const redisClientProviders = (0, redis_providers_1.createRedisClientProviders)(); | ||
| const providers = [ | ||
| ...(0, redis_providers_1.createAsyncProviders)(options), | ||
| redis_providers_1.redisClientsProvider, | ||
| redis_providers_1.mergedOptionsProvider, | ||
| redis_manager_1.RedisManager, | ||
| ...redisClientProviders, | ||
| ...((_a = options.extraProviders) !== null && _a !== void 0 ? _a : []) | ||
| ]; | ||
| return { | ||
| global: isGlobal, | ||
| module: RedisModule_1, | ||
| imports: options.imports, | ||
| providers, | ||
| exports: [redis_manager_1.RedisManager, ...redisClientProviders] | ||
| }; | ||
| } | ||
| async onApplicationShutdown() { | ||
| const { closeClient } = this.moduleRef.get(redis_constants_1.REDIS_MERGED_OPTIONS, { strict: false }); | ||
| if (closeClient) { | ||
| const results = await (0, common_2.destroy)(this.moduleRef.get(redis_constants_1.REDIS_CLIENTS, { strict: false })); | ||
| results.forEach(([namespace, quit]) => { | ||
| if ((0, utils_1.isResolution)(namespace) && (0, utils_1.isRejection)(quit) && (0, utils_1.isError)(quit.reason)) { | ||
| redis_logger_1.logger.error((0, messages_1.ERROR_LOG)((0, utils_1.parseNamespace)(namespace.value), quit.reason.message), quit.reason.stack); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| }; | ||
| RedisModule = RedisModule_1 = tslib_1.__decorate([ | ||
| (0, common_1.Module)({}), | ||
| tslib_1.__metadata("design:paramtypes", [core_1.ModuleRef]) | ||
| ], RedisModule); | ||
| exports.RedisModule = RedisModule; |
| import { Provider, FactoryProvider, ValueProvider } from '@nestjs/common'; | ||
| import type { Redis } from 'ioredis'; | ||
| import { RedisModuleOptions, RedisModuleAsyncOptions, RedisOptionsFactory, RedisClients } from './interfaces'; | ||
| export declare const createOptionsProvider: (options: RedisModuleOptions) => ValueProvider<RedisModuleOptions>; | ||
| export declare const createAsyncProviders: (options: RedisModuleAsyncOptions) => Provider[]; | ||
| export declare const createAsyncOptions: (optionsFactory: RedisOptionsFactory) => Promise<RedisModuleOptions>; | ||
| export declare const createAsyncOptionsProvider: (options: RedisModuleAsyncOptions) => Provider; | ||
| export declare const createRedisClientProviders: () => FactoryProvider<Redis>[]; | ||
| export declare const redisClientsProvider: FactoryProvider<RedisClients>; | ||
| export declare const mergedOptionsProvider: FactoryProvider<RedisModuleOptions>; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.mergedOptionsProvider = exports.redisClientsProvider = exports.createRedisClientProviders = exports.createAsyncOptionsProvider = exports.createAsyncOptions = exports.createAsyncProviders = exports.createOptionsProvider = void 0; | ||
| const redis_constants_1 = require("./redis.constants"); | ||
| const common_1 = require("./common"); | ||
| const redis_manager_1 = require("./redis-manager"); | ||
| const default_options_1 = require("./default-options"); | ||
| const createOptionsProvider = (options) => ({ | ||
| provide: redis_constants_1.REDIS_OPTIONS, | ||
| useValue: options | ||
| }); | ||
| exports.createOptionsProvider = createOptionsProvider; | ||
| const createAsyncProviders = (options) => { | ||
| if (options.useClass) { | ||
| return [ | ||
| { | ||
| provide: options.useClass, | ||
| useClass: options.useClass | ||
| }, | ||
| (0, exports.createAsyncOptionsProvider)(options) | ||
| ]; | ||
| } | ||
| if (options.useExisting || options.useFactory) | ||
| return [(0, exports.createAsyncOptionsProvider)(options)]; | ||
| return []; | ||
| }; | ||
| exports.createAsyncProviders = createAsyncProviders; | ||
| const createAsyncOptions = async (optionsFactory) => { | ||
| return await optionsFactory.createRedisOptions(); | ||
| }; | ||
| exports.createAsyncOptions = createAsyncOptions; | ||
| const createAsyncOptionsProvider = (options) => { | ||
| if (options.useFactory) { | ||
| return { | ||
| provide: redis_constants_1.REDIS_OPTIONS, | ||
| useFactory: options.useFactory, | ||
| inject: options.inject | ||
| }; | ||
| } | ||
| if (options.useClass) { | ||
| return { | ||
| provide: redis_constants_1.REDIS_OPTIONS, | ||
| useFactory: exports.createAsyncOptions, | ||
| inject: [options.useClass] | ||
| }; | ||
| } | ||
| if (options.useExisting) { | ||
| return { | ||
| provide: redis_constants_1.REDIS_OPTIONS, | ||
| useFactory: exports.createAsyncOptions, | ||
| inject: [options.useExisting] | ||
| }; | ||
| } | ||
| return { | ||
| provide: redis_constants_1.REDIS_OPTIONS, | ||
| useValue: {} | ||
| }; | ||
| }; | ||
| exports.createAsyncOptionsProvider = createAsyncOptionsProvider; | ||
| const createRedisClientProviders = () => { | ||
| const providers = []; | ||
| common_1.namespaces.forEach((token, namespace) => { | ||
| providers.push({ | ||
| provide: token, | ||
| useFactory: (redisManager) => redisManager.getClient(namespace), | ||
| inject: [redis_manager_1.RedisManager] | ||
| }); | ||
| }); | ||
| return providers; | ||
| }; | ||
| exports.createRedisClientProviders = createRedisClientProviders; | ||
| exports.redisClientsProvider = { | ||
| provide: redis_constants_1.REDIS_CLIENTS, | ||
| useFactory: (options) => { | ||
| var _a; | ||
| const clients = new Map(); | ||
| if (Array.isArray(options.config)) { | ||
| options.config.forEach(item => { | ||
| var _a; | ||
| return clients.set((_a = item.namespace) !== null && _a !== void 0 ? _a : redis_constants_1.DEFAULT_REDIS_NAMESPACE, (0, common_1.createClient)(Object.assign(Object.assign({}, options.commonOptions), item), { readyLog: options.readyLog, errorLog: options.errorLog })); | ||
| }); | ||
| } | ||
| else if (options.config) { | ||
| clients.set((_a = options.config.namespace) !== null && _a !== void 0 ? _a : redis_constants_1.DEFAULT_REDIS_NAMESPACE, (0, common_1.createClient)(options.config, { readyLog: options.readyLog, errorLog: options.errorLog })); | ||
| } | ||
| return clients; | ||
| }, | ||
| inject: [redis_constants_1.REDIS_MERGED_OPTIONS] | ||
| }; | ||
| exports.mergedOptionsProvider = { | ||
| provide: redis_constants_1.REDIS_MERGED_OPTIONS, | ||
| useFactory: (options) => (Object.assign(Object.assign({}, default_options_1.defaultRedisModuleOptions), options)), | ||
| inject: [redis_constants_1.REDIS_OPTIONS] | ||
| }; |
| export * from './is'; | ||
| export * from './parsers'; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const tslib_1 = require("tslib"); | ||
| tslib_1.__exportStar(require("./is"), exports); | ||
| tslib_1.__exportStar(require("./parsers"), exports); |
| /** | ||
| * Returns `true` if the value is of type `string`. | ||
| * | ||
| * @param value - Any value | ||
| */ | ||
| export declare const isString: (value: unknown) => value is string; | ||
| /** | ||
| * Returns `true` if the value is of type `symbol`. | ||
| * | ||
| * @param value - Any value | ||
| */ | ||
| export declare const isSymbol: (value: unknown) => value is symbol; | ||
| /** | ||
| * Returns `true` if the value is an instance of `Error`. | ||
| * | ||
| * @param value - Any value | ||
| */ | ||
| export declare const isError: (value: unknown) => value is Error; | ||
| /** | ||
| * Returns `true` if the value is of type `PromiseFulfilledResult`. | ||
| * | ||
| * @param value - `PromiseSettledResult` | ||
| */ | ||
| export declare const isResolution: <T>(value: PromiseSettledResult<T>) => value is PromiseFulfilledResult<T>; | ||
| /** | ||
| * Returns `true` if the value is of type `PromiseRejectedResult`. | ||
| * | ||
| * @param value - `PromiseSettledResult` | ||
| */ | ||
| export declare const isRejection: (value: PromiseSettledResult<unknown>) => value is PromiseRejectedResult; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.isRejection = exports.isResolution = exports.isError = exports.isSymbol = exports.isString = void 0; | ||
| /** | ||
| * Returns `true` if the value is of type `string`. | ||
| * | ||
| * @param value - Any value | ||
| */ | ||
| const isString = (value) => typeof value === 'string'; | ||
| exports.isString = isString; | ||
| /** | ||
| * Returns `true` if the value is of type `symbol`. | ||
| * | ||
| * @param value - Any value | ||
| */ | ||
| const isSymbol = (value) => typeof value === 'symbol'; | ||
| exports.isSymbol = isSymbol; | ||
| /** | ||
| * Returns `true` if the value is an instance of `Error`. | ||
| * | ||
| * @param value - Any value | ||
| */ | ||
| const isError = (value) => { | ||
| const typeName = Object.prototype.toString.call(value).slice(8, -1); | ||
| return typeName === 'Error'; | ||
| }; | ||
| exports.isError = isError; | ||
| /** | ||
| * Returns `true` if the value is of type `PromiseFulfilledResult`. | ||
| * | ||
| * @param value - `PromiseSettledResult` | ||
| */ | ||
| const isResolution = (value) => { | ||
| return value.status === 'fulfilled'; | ||
| }; | ||
| exports.isResolution = isResolution; | ||
| /** | ||
| * Returns `true` if the value is of type `PromiseRejectedResult`. | ||
| * | ||
| * @param value - `PromiseSettledResult` | ||
| */ | ||
| const isRejection = (value) => { | ||
| return value.status === 'rejected'; | ||
| }; | ||
| exports.isRejection = isRejection; |
| import { ClientNamespace } from '../interfaces'; | ||
| /** | ||
| * Parses namespace to string. | ||
| * | ||
| * @param namespace - The namespace of the client | ||
| */ | ||
| export declare const parseNamespace: (namespace: ClientNamespace) => string; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.parseNamespace = void 0; | ||
| const is_1 = require("./is"); | ||
| /** | ||
| * Parses namespace to string. | ||
| * | ||
| * @param namespace - The namespace of the client | ||
| */ | ||
| const parseNamespace = (namespace) => (0, is_1.isString)(namespace) ? namespace : namespace.toString(); | ||
| exports.parseNamespace = parseNamespace; |
+21
| MIT License | ||
| Copyright (c) 2023 LiaoLiao | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
+47
-51
| { | ||
| "name": "@voiceflow/nestjs-redis", | ||
| "description": "Redis for NestJS", | ||
| "version": "1.2.1", | ||
| "author": "Voiceflow", | ||
| "bugs": { | ||
| "url": "https://github.com/voiceflow/libs/issues" | ||
| }, | ||
| "dependencies": { | ||
| "@voiceflow/nestjs-common": "^1.5.1" | ||
| }, | ||
| "devDependencies": { | ||
| "@nestjs/common": "^8.4.2", | ||
| "@nestjs/core": "^8.4.2", | ||
| "@nestjs/terminus": "^8.0.6", | ||
| "@nestjs/testing": "^8.4.2", | ||
| "@types/ioredis": "^4.28.10", | ||
| "ioredis": "^4.28.5" | ||
| }, | ||
| "engines": { | ||
| "node": ">=16" | ||
| }, | ||
| "version": "9.0.6", | ||
| "description": "Redis(ioredis) module for Nest framework (node.js).", | ||
| "author": "LiaoLiao <yxiaosong002@gmail.com>", | ||
| "main": "dist/index.js", | ||
| "types": "dist/index.d.ts", | ||
| "files": [ | ||
| "build" | ||
| "dist" | ||
| ], | ||
| "homepage": "https://github.com/voiceflow/libs#readme", | ||
| "license": "MIT", | ||
| "keywords": [ | ||
| "redis", | ||
| "ioredis", | ||
| "sentinel", | ||
| "cluster", | ||
| "nestjs", | ||
| "redis", | ||
| "voiceflow" | ||
| "nest", | ||
| "nodejs", | ||
| "node", | ||
| "typescript", | ||
| "javascript" | ||
| ], | ||
| "license": "ISC", | ||
| "main": "build/index.js", | ||
| "dependencies": { | ||
| "tslib": "2.4.1" | ||
| }, | ||
| "peerDependencies": { | ||
| "@nestjs/common": "^8.4.2", | ||
| "@nestjs/terminus": "^8.0.6", | ||
| "ioredis": "^4.28.5" | ||
| "@nestjs/common": "^9.0.0", | ||
| "@nestjs/core": "^9.0.0", | ||
| "ioredis": "^5.0.0" | ||
| }, | ||
| "engines": { | ||
| "node": ">=12.22.0" | ||
| }, | ||
| "publishConfig": { | ||
| "access": "public", | ||
| "main": "build/index.d.ts" | ||
| "access": "public" | ||
| }, | ||
| "homepage": "https://github.com/liaoliaots/nestjs-redis#readme", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/voiceflow/libs.git" | ||
| "url": "git+https://github.com/liaoliaots/nestjs-redis.git" | ||
| }, | ||
| "bugs": { | ||
| "url": "https://github.com/liaoliaots/nestjs-redis/issues" | ||
| }, | ||
| "scripts": { | ||
| "build": "ttsc --build tsconfig.build.json", | ||
| "clean": "rimraf build *.tsbuildinfo", | ||
| "commit": "cz", | ||
| "lint": "eslint '**/*.{js,ts}'", | ||
| "lint:fix": "yarn lint --fix", | ||
| "lint:quiet": "yarn lint --quiet", | ||
| "lint:report": "eslint-output --quiet '**/*.{js,ts}'", | ||
| "prebuild": "yarn clean", | ||
| "tdd": "yarn test --watch", | ||
| "test": "yarn test:run", | ||
| "test:dependencies": "depcheck", | ||
| "test:integration": "NODE_ENV=test nyc --report-dir nyc_coverage_integration ts-mocha --paths --config config/tests/mocharc.yml 'tests/**/*.it.ts'", | ||
| "test:run": "NODE_ENV=test nyc ts-mocha --paths --config config/tests/mocharc.yml 'tests/**/*.{unit,it}.ts'", | ||
| "test:single": "NODE_ENV=test ts-mocha --paths --config config/tests/mocharc.yml", | ||
| "test:unit": "NODE_ENV=test nyc --report-dir=nyc_coverage_unit ts-mocha --paths --config config/tests/mocharc.yml 'tests/**/*.unit.ts'" | ||
| }, | ||
| "types": "build/index.d.ts", | ||
| "gitHead": "ca02c328faf4ff3ae771ba44ca358d710aab48cb" | ||
| } | ||
| "prebuild": "rimraf dist", | ||
| "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json", | ||
| "lint": "concurrently \"npm:lint:es\" \"npm:lint:tsc\"", | ||
| "lint:es": "eslint \"{lib,test}/**/*.ts\"", | ||
| "lint:tsc": "tsc -p tsconfig.json --noEmit", | ||
| "test": "jest", | ||
| "test:watch": "jest --watch", | ||
| "test:cov": "jest --coverage", | ||
| "test:e2e": "jest --config ./test/jest-e2e.json", | ||
| "test:clear": "jest --clearCache", | ||
| "make-badges": "istanbul-badges-readme --coverageDir=\"./coverage\" --readmeDir=\"./\" --style=\"flat-square\" --logo=\"jest\"", | ||
| "madge": "madge --image ./dependency-graph.svg dist/index.js", | ||
| "publish:next": "npm publish --tag next", | ||
| "publish:rc": "npm publish --tag rc" | ||
| } | ||
| } |
+235
-28
@@ -1,10 +0,93 @@ | ||
| # NestJS Redis | ||
| [![NPM][npm-shield]][npm-url] | ||
| [![Downloads][downloads-shield]][downloads-url] | ||
| [![Stargazers][stars-shield]][stars-url] | ||
| [![Issues][issues-shield]][issues-url] | ||
| [![License][license-shield]][license-url] | ||
| ![Vulnerabilities][vulnerabilities-shield] | ||
| [![Workflow][workflow-shield]][workflow-url] | ||
| Redis, but for NestJS | ||
| <p align="center"> | ||
| <a href="https://nestjs.com/"> | ||
| <img src="https://nestjs.com/img/logo-small.svg" alt="Nest Logo" width="120"> | ||
| </a> | ||
| </p> | ||
| ## Installation | ||
| <div align="center"> | ||
| <h1 align="center">Nest Redis Module</h1> | ||
| <p align="center"> | ||
| Redis(ioredis) module for Nest framework (node.js). | ||
| <br /> | ||
| <a href="#usage"><strong>Explore the docs »</strong></a> | ||
| <br /> | ||
| <br /> | ||
| <a href="/sample">View Demos</a> | ||
| · | ||
| <a href="https://github.com/liaoliaots/nestjs-redis/issues/new/choose">Report Bug</a> | ||
| · | ||
| <a href="https://github.com/liaoliaots/nestjs-redis/issues">Request Feature</a> | ||
| </p> | ||
| </div> | ||
| <details> | ||
| <summary>Table of Contents</summary> | ||
| <ol> | ||
| <li> | ||
| <a href="#about-the-project">About The Project</a> | ||
| <ul> | ||
| <li><a href="#features">Features</a></li> | ||
| <li><a href="#test-coverage">Test coverage</a></li> | ||
| </ul> | ||
| </li> | ||
| <li> | ||
| <a href="#getting-started">Getting Started</a> | ||
| <ul> | ||
| <li><a href="#prerequisites">Prerequisites</a></li> | ||
| <li><a href="#installation">Installation</a></li> | ||
| </ul> | ||
| </li> | ||
| <li><a href="#usage">Usage</a></li> | ||
| <li><a href="#faqs">FAQs</a></li> | ||
| <li><a href="#roadmap">Roadmap</a></li> | ||
| <li><a href="#contributing">Contributing</a></li> | ||
| <li><a href="#license">License</a></li> | ||
| <li><a href="#acknowledgments">Acknowledgments</a></li> | ||
| </ol> | ||
| </details> | ||
| ## About The Project | ||
| ### Features | ||
| - **Both redis & cluster are supported**: You can also specify multiple instances. | ||
| - **Health**: Checks health of **redis & cluster** server. | ||
| - **Rigorously tested**: With 100+ tests and 100% code coverage. | ||
| - **Decorators**: Injects **redis & cluster** clients via `@InjectRedis()`, `@InjectCluster()`. | ||
| - **Services**: Retrieves **redis & cluster** clients via `RedisService`, `ClusterService`. | ||
| - **Testing**: Generates an injection token via `getRedisToken`, `getClusterToken`. | ||
| ### Test coverage | ||
| | Statements | Branches | Functions | Lines | | ||
| | --------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | | ||
| |  |  |  |  | | ||
| ## Getting Started | ||
| ### Prerequisites | ||
| This lib requires **Node.js >=12.22.0**, **NestJS ^9.0.0**, **ioredis ^5.0.0**. | ||
| - If you depend on **ioredis 4**, please use [version 7](https://github.com/liaoliaots/nestjs-redis/tree/v7.0.0) of the lib. | ||
| - If you depend on **ioredis 5**, **NestJS 7** or **8**, please use [version 8](https://github.com/liaoliaots/nestjs-redis/tree/v8.2.2) of the lib. | ||
| ### Installation | ||
| ```sh | ||
| yarn add @voiceflow/nestjs-redis ioredis | ||
| yarn add -D @types/ioredis | ||
| # with npm | ||
| npm install @liaoliaots/nestjs-redis ioredis | ||
| # with yarn | ||
| yarn add @liaoliaots/nestjs-redis ioredis | ||
| # with pnpm | ||
| pnpm add @liaoliaots/nestjs-redis ioredis | ||
| ``` | ||
@@ -14,25 +97,91 @@ | ||
| The redis module can be setup in a couple different ways using `forRootAsync`: | ||
| - [Redis](/docs/latest/redis.md) | ||
| - [Usage](/docs/latest/redis.md) | ||
| - [Configuration](/docs/latest/redis.md#configuration) | ||
| - [Testing](/docs/latest/redis.md#testing) | ||
| - [Non-Global](/docs/latest/redis.md#non-global) | ||
| - [Auto-reconnect](https://luin.github.io/ioredis/interfaces/CommonRedisOptions.html#retryStrategy) | ||
| - [Unix domain socket](/docs/latest/redis.md#unix-domain-socket) | ||
| - [Cluster](/docs/latest/cluster.md) | ||
| - [Usage](/docs/latest/cluster.md) | ||
| - [Configuration](/docs/latest/cluster.md#configuration) | ||
| - [Testing](/docs/latest/cluster.md#testing) | ||
| - [Non-Global](/docs/latest/cluster.md#non-global) | ||
| - [Auto-reconnect](https://luin.github.io/ioredis/interfaces/ClusterOptions.html#clusterRetryStrategy) | ||
| - [Health Checks](/packages/redis-health/README.md) | ||
| - [Examples](/docs/latest/examples.md) | ||
| - [Redis Sentinel](/docs/latest/examples.md#sentinel) | ||
| - A `RedisOptions` object can be provided via `useValue`. | ||
| - A `useFactory` function can be provided to return a `RedisOptions` object (or a promise for one!). | ||
| - A class implementing `RedisOptions` can be provided using `useClass`. | ||
| ### Legacy | ||
| - version 7, [click here](/docs/v7) | ||
| - version 8, [click here](/docs/v8) | ||
| ## FAQs | ||
| ### Circular dependency ⚠️ | ||
| <details> | ||
| <summary>Click to expand</summary> | ||
| [A circular dependency](https://docs.nestjs.com/fundamentals/circular-dependency) might also be caused when using "barrel files"/index.ts files to group imports. Barrel files should be omitted when it comes to module/provider classes. For example, barrel files should not be used when importing files within the same directory as the barrel file, i.e. `cats/cats.controller` should not import `cats` to import the `cats/cats.service` file. For more details please also see [this github issue](https://github.com/nestjs/nest/issues/1181#issuecomment-430197191). | ||
| </details> | ||
| ### "Cannot resolve dependency" error | ||
| <details> | ||
| <summary>Click to expand</summary> | ||
| If you encountered an error like this: | ||
| ``` | ||
| Nest can't resolve dependencies of the <provider> (?). Please make sure that the argument <unknown_token> at index [<index>] is available in the <module> context. | ||
| Potential solutions: | ||
| - If <unknown_token> is a provider, is it part of the current <module>? | ||
| - If <unknown_token> is exported from a separate @Module, is that module imported within <module>? | ||
| @Module({ | ||
| imports: [ /* the Module containing <unknown_token> */ ] | ||
| }) | ||
| ``` | ||
| Please make sure that the `RedisModule` is added directly to the `imports` array of `@Module()` decorator of "Root Module"(if `isGlobal` is true) or "Feature Module"(if `isGlobal` is false). | ||
| Examples of code: | ||
| ```ts | ||
| import { RedisModule, RedisService, RedisOptions } from '@voiceflow/nestjs-redis'; | ||
| // redis-config.service.ts | ||
| import { Injectable } from '@nestjs/common'; | ||
| import { RedisModuleOptions, RedisOptionsFactory } from '@liaoliaots/nestjs-redis'; | ||
| @Injectable() | ||
| export class RedisConfigService implements RedisOptionsFactory { | ||
| createRedisOptions(): RedisModuleOptions { | ||
| return { | ||
| readyLog: true, | ||
| config: { | ||
| host: 'localhost', | ||
| port: 6379, | ||
| password: 'authpassword' | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| ``` | ||
| ### ✅ Correct | ||
| ```ts | ||
| // app.module.ts | ||
| import { Module } from '@nestjs/common'; | ||
| import { RedisModule } from '@liaoliaots/nestjs-redis'; | ||
| import { RedisConfigService } from './redis-config.service'; | ||
| @Module({ | ||
| imports: [ | ||
| RedisModule.forRootAsync({ | ||
| imports: [], | ||
| // Union field, one of `useValue`, `useFactory`, or `useClass`: | ||
| useValue: { | ||
| host: '0.0.0.0', | ||
| port: 6379, | ||
| }, | ||
| useFactory: () => getRedisConfig(), | ||
| useClass: RedisConfigService, | ||
| }), | ||
| ], | ||
| useClass: RedisConfigService | ||
| }) | ||
| ] | ||
| }) | ||
@@ -42,17 +191,75 @@ export class AppModule {} | ||
| If you have an existing redis connection that you'd like to reuse, you can provide that in `forRoot`. | ||
| ### ❌ Incorrect | ||
| ```ts | ||
| import IORedis from 'ioredis'; | ||
| // my-redis.module.ts | ||
| import { Module } from '@nestjs/common'; | ||
| import { RedisModule } from '@liaoliaots/nestjs-redis'; | ||
| import { RedisConfigService } from './redis-config.service'; | ||
| const redisConnection = new IORedis(...); | ||
| @Module({ | ||
| imports: [ | ||
| RedisModule.forRoot(redisConnection), | ||
| ], | ||
| RedisModule.forRootAsync({ | ||
| useClass: RedisConfigService | ||
| }) | ||
| ] | ||
| }) | ||
| export class MyRedisModule {} | ||
| ``` | ||
| ```ts | ||
| // app.module.ts | ||
| import { Module } from '@nestjs/common'; | ||
| import { MyRedisModule } from './my-redis.module'; | ||
| @Module({ | ||
| imports: [MyRedisModule] | ||
| }) | ||
| export class AppModule {} | ||
| ``` | ||
| Once the `RedisModule` is globally registered, `RedisService` can be injected in other providers without having to import `RedisModule` again. | ||
| </details> | ||
| ## Roadmap | ||
| - [x] Compatible with **NestJS ^9** | ||
| - [ ] Flexible custom logger | ||
| - [ ] Add some examples for **TLS** | ||
| ## Contributing | ||
| Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**. | ||
| If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". | ||
| Don't forget to give the project a star! Thanks again! | ||
| 1. Fork the Project | ||
| 2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`) | ||
| 3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`) | ||
| 4. Push to the Branch (`git push origin feature/AmazingFeature`) | ||
| 5. Open a Pull Request | ||
| ## License | ||
| Distributed under the MIT License. See `LICENSE` for more information. | ||
| ## Acknowledgments | ||
| - [Full-Featured Redis Client - ioredis](https://github.com/luin/ioredis) | ||
| - [Official Redis Documentation](https://redis.io/) | ||
| - [Official Redis Docker Image](https://hub.docker.com/_/redis) | ||
| - [Official Bitnami Redis Docker Image](https://hub.docker.com/r/bitnami/redis) | ||
| [npm-shield]: https://img.shields.io/npm/v/@liaoliaots/nestjs-redis/latest?style=for-the-badge | ||
| [npm-url]: https://www.npmjs.com/package/@liaoliaots/nestjs-redis | ||
| [downloads-shield]: https://img.shields.io/npm/dm/@liaoliaots/nestjs-redis?style=for-the-badge | ||
| [downloads-url]: https://www.npmjs.com/package/@liaoliaots/nestjs-redis | ||
| [stars-shield]: https://img.shields.io/github/stars/liaoliaots/nestjs-redis?style=for-the-badge | ||
| [stars-url]: https://github.com/liaoliaots/nestjs-redis/stargazers | ||
| [issues-shield]: https://img.shields.io/github/issues/liaoliaots/nestjs-redis?style=for-the-badge | ||
| [issues-url]: https://github.com/liaoliaots/nestjs-redis/issues | ||
| [license-shield]: https://img.shields.io/npm/l/@liaoliaots/nestjs-redis?style=for-the-badge | ||
| [license-url]: https://github.com/liaoliaots/nestjs-redis/blob/main/LICENSE | ||
| [vulnerabilities-shield]: https://img.shields.io/snyk/vulnerabilities/npm/@liaoliaots/nestjs-redis?style=for-the-badge | ||
| [workflow-shield]: https://img.shields.io/github/actions/workflow/status/liaoliaots/nestjs-redis/testing.yaml?label=TESTING&style=for-the-badge | ||
| [workflow-url]: https://github.com/liaoliaots/nestjs-redis/actions/workflows/testing.yaml |
| export declare const Providers: { | ||
| readonly REDIS_CONNECTION: symbol; | ||
| readonly REDIS_OPTIONS: symbol; | ||
| }; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.Providers = void 0; | ||
| exports.Providers = { | ||
| REDIS_CONNECTION: Symbol('@voiceflow/nestjs-redis RedisConnection'), | ||
| REDIS_OPTIONS: Symbol('@voiceflow/nestjs-redis RedisOptions'), | ||
| }; | ||
| //# sourceMappingURL=constants.js.map |
| {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG;IACvB,gBAAgB,EAAE,MAAM,CAAC,yCAAyC,CAAC;IACnE,aAAa,EAAE,MAAM,CAAC,sCAAsC,CAAC;CACrD,CAAC"} |
| export * from './constants'; | ||
| export * from './interfaces/options.interface'; | ||
| export { RedisHealthIndicator } from './redis.health'; | ||
| export { RedisModule } from './redis.module'; | ||
| export { RedisService } from './redis.service'; |
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
| for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.RedisService = exports.RedisModule = exports.RedisHealthIndicator = void 0; | ||
| __exportStar(require("./constants"), exports); | ||
| __exportStar(require("./interfaces/options.interface"), exports); | ||
| var redis_health_1 = require("./redis.health"); | ||
| Object.defineProperty(exports, "RedisHealthIndicator", { enumerable: true, get: function () { return redis_health_1.RedisHealthIndicator; } }); | ||
| var redis_module_1 = require("./redis.module"); | ||
| Object.defineProperty(exports, "RedisModule", { enumerable: true, get: function () { return redis_module_1.RedisModule; } }); | ||
| var redis_service_1 = require("./redis.service"); | ||
| Object.defineProperty(exports, "RedisService", { enumerable: true, get: function () { return redis_service_1.RedisService; } }); | ||
| //# sourceMappingURL=index.js.map |
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,iEAA+C;AAC/C,+CAAsD;AAA7C,oHAAA,oBAAoB,OAAA;AAC7B,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AACpB,iDAA+C;AAAtC,6GAAA,YAAY,OAAA"} |
| import { ModuleMetadata, Type } from '@nestjs/common'; | ||
| import type { Redis, RedisOptions as IORedisOptions } from 'ioredis'; | ||
| export declare type RedisConnection = Redis; | ||
| export interface RedisOptions { | ||
| host: string; | ||
| port: number; | ||
| ioredis?: Omit<IORedisOptions, 'host' | 'port'>; | ||
| } | ||
| export interface RedisModuleAsyncOptions extends Pick<ModuleMetadata, 'providers' | 'imports'> { | ||
| useClass?: Type<RedisOptions>; | ||
| useFactory?: (...args: any[]) => PromiseLike<RedisOptions> | RedisOptions; | ||
| useValue?: RedisOptions; | ||
| inject?: any[]; | ||
| } |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| //# sourceMappingURL=options.interface.js.map |
| {"version":3,"file":"options.interface.js","sourceRoot":"","sources":["../../src/interfaces/options.interface.ts"],"names":[],"mappings":""} |
| import type { HealthIndicatorResult } from '@nestjs/terminus'; | ||
| import { HealthIndicator } from '@nestjs/terminus'; | ||
| import { RedisService } from './redis.service'; | ||
| export declare class RedisHealthIndicator extends HealthIndicator { | ||
| private readonly redisService; | ||
| constructor(redisService: RedisService); | ||
| isHealthy(key: string): Promise<HealthIndicatorResult>; | ||
| } |
| "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); | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.RedisHealthIndicator = void 0; | ||
| const common_1 = require("@nestjs/common"); | ||
| const terminus_1 = require("@nestjs/terminus"); | ||
| const nestjs_common_1 = require("@voiceflow/nestjs-common"); | ||
| const redis_service_1 = require("./redis.service"); | ||
| let RedisHealthIndicator = class RedisHealthIndicator extends terminus_1.HealthIndicator { | ||
| constructor(redisService) { | ||
| super(); | ||
| this.redisService = redisService; | ||
| } | ||
| async isHealthy(key) { | ||
| let isHealthy; | ||
| let data; | ||
| try { | ||
| const pingResponse = await this.redisService.connection.ping(); | ||
| isHealthy = true; | ||
| data = { response: pingResponse }; | ||
| } | ||
| catch (error) { | ||
| isHealthy = false; | ||
| data = new nestjs_common_1.HealthCheckErrorDto(error); | ||
| } | ||
| const result = this.getStatus(key, isHealthy, data); | ||
| if (isHealthy) { | ||
| return result; | ||
| } | ||
| throw new terminus_1.HealthCheckError('Redis health check failed', result); | ||
| } | ||
| }; | ||
| RedisHealthIndicator = __decorate([ | ||
| (0, common_1.Injectable)(), | ||
| __metadata("design:paramtypes", [redis_service_1.RedisService]) | ||
| ], RedisHealthIndicator); | ||
| exports.RedisHealthIndicator = RedisHealthIndicator; | ||
| //# sourceMappingURL=redis.health.js.map |
| {"version":3,"file":"redis.health.js","sourceRoot":"","sources":["../src/redis.health.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAE5C,+CAAqE;AACrE,4DAA+D;AAE/D,mDAA+C;AAG/C,IAAa,oBAAoB,GAAjC,MAAa,oBAAqB,SAAQ,0BAAe;IACvD,YAA6B,YAA0B;QACrD,KAAK,EAAE,CAAC;QADmB,iBAAY,GAAZ,YAAY,CAAc;IAEvD,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,GAAW;QACzB,IAAI,SAAkB,CAAC;QACvB,IAAI,IAAgD,CAAC;QAErD,IAAI;YACF,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;YAE/D,SAAS,GAAG,IAAI,CAAC;YACjB,IAAI,GAAG,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC;SACnC;QAAC,OAAO,KAAK,EAAE;YACd,SAAS,GAAG,KAAK,CAAC;YAElB,IAAI,GAAG,IAAI,mCAAmB,CAAC,KAAK,CAAC,CAAC;SACvC;QAED,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;QAEpD,IAAI,SAAS,EAAE;YACb,OAAO,MAAM,CAAC;SACf;QAED,MAAM,IAAI,2BAAgB,CAAC,2BAA2B,EAAE,MAAM,CAAC,CAAC;IAClE,CAAC;CACF,CAAA;AA5BY,oBAAoB;IADhC,IAAA,mBAAU,GAAE;qCAEgC,4BAAY;GAD5C,oBAAoB,CA4BhC;AA5BY,oDAAoB"} |
| import { DynamicModule } from '@nestjs/common'; | ||
| import { RedisConnection, RedisModuleAsyncOptions } from './interfaces/options.interface'; | ||
| export declare class RedisModule { | ||
| static forRoot(connection: RedisConnection): DynamicModule; | ||
| static forRootAsync(options: RedisModuleAsyncOptions): DynamicModule; | ||
| } |
| "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 RedisModule_1; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.RedisModule = void 0; | ||
| const common_1 = require("@nestjs/common"); | ||
| const constants_1 = require("./constants"); | ||
| const redis_health_1 = require("./redis.health"); | ||
| const redis_service_1 = require("./redis.service"); | ||
| let RedisModule = RedisModule_1 = class RedisModule { | ||
| static forRoot(connection) { | ||
| return { | ||
| global: true, | ||
| module: RedisModule_1, | ||
| providers: [{ provide: constants_1.Providers.REDIS_CONNECTION, useValue: connection }, redis_service_1.RedisService, redis_health_1.RedisHealthIndicator], | ||
| exports: [redis_health_1.RedisHealthIndicator, redis_service_1.RedisService], | ||
| }; | ||
| } | ||
| static forRootAsync(options) { | ||
| var _a, _b, _c, _d, _e, _f; | ||
| if (options.useFactory) { | ||
| return { | ||
| global: true, | ||
| module: RedisModule_1, | ||
| imports: options.imports, | ||
| providers: [ | ||
| { | ||
| provide: constants_1.Providers.REDIS_OPTIONS, | ||
| useFactory: options.useFactory, | ||
| inject: (_a = options.inject) !== null && _a !== void 0 ? _a : [], | ||
| }, | ||
| redis_service_1.RedisService.connectionFactory, | ||
| redis_service_1.RedisService, | ||
| redis_health_1.RedisHealthIndicator, | ||
| ...((_b = options.providers) !== null && _b !== void 0 ? _b : []), | ||
| ], | ||
| exports: [redis_health_1.RedisHealthIndicator, redis_service_1.RedisService], | ||
| }; | ||
| } | ||
| if (options.useClass) { | ||
| return { | ||
| global: true, | ||
| module: RedisModule_1, | ||
| imports: options.imports, | ||
| providers: [ | ||
| { | ||
| provide: constants_1.Providers.REDIS_OPTIONS, | ||
| useClass: options.useClass, | ||
| inject: (_c = options.inject) !== null && _c !== void 0 ? _c : [], | ||
| }, | ||
| redis_service_1.RedisService.connectionFactory, | ||
| redis_service_1.RedisService, | ||
| redis_health_1.RedisHealthIndicator, | ||
| ...((_d = options.providers) !== null && _d !== void 0 ? _d : []), | ||
| ], | ||
| exports: [redis_health_1.RedisHealthIndicator, redis_service_1.RedisService], | ||
| }; | ||
| } | ||
| if (options.useValue) { | ||
| return { | ||
| global: true, | ||
| module: RedisModule_1, | ||
| imports: options.imports, | ||
| providers: [ | ||
| { | ||
| provide: constants_1.Providers.REDIS_OPTIONS, | ||
| useValue: options.useValue, | ||
| inject: (_e = options.inject) !== null && _e !== void 0 ? _e : [], | ||
| }, | ||
| redis_service_1.RedisService.connectionFactory, | ||
| redis_service_1.RedisService, | ||
| redis_health_1.RedisHealthIndicator, | ||
| ...((_f = options.providers) !== null && _f !== void 0 ? _f : []), | ||
| ], | ||
| exports: [redis_health_1.RedisHealthIndicator, redis_service_1.RedisService], | ||
| }; | ||
| } | ||
| throw new RangeError('Expected a useValue, useFactory, or useClass value to be present in the options'); | ||
| } | ||
| }; | ||
| RedisModule = RedisModule_1 = __decorate([ | ||
| (0, common_1.Module)({}) | ||
| ], RedisModule); | ||
| exports.RedisModule = RedisModule; | ||
| //# sourceMappingURL=redis.module.js.map |
| {"version":3,"file":"redis.module.js","sourceRoot":"","sources":["../src/redis.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuD;AAEvD,2CAAwC;AAExC,iDAAsD;AACtD,mDAA+C;AAG/C,IAAa,WAAW,mBAAxB,MAAa,WAAW;IACtB,MAAM,CAAC,OAAO,CAAC,UAA2B;QACxC,OAAO;YACL,MAAM,EAAE,IAAI;YACZ,MAAM,EAAE,aAAW;YACnB,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,qBAAS,CAAC,gBAAgB,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,4BAAY,EAAE,mCAAoB,CAAC;YAC9G,OAAO,EAAE,CAAC,mCAAoB,EAAE,4BAAY,CAAC;SAC9C,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,OAAgC;;QAClD,IAAI,OAAO,CAAC,UAAU,EAAE;YACtB,OAAO;gBACL,MAAM,EAAE,IAAI;gBACZ,MAAM,EAAE,aAAW;gBACnB,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,SAAS,EAAE;oBACT;wBACE,OAAO,EAAE,qBAAS,CAAC,aAAa;wBAChC,UAAU,EAAE,OAAO,CAAC,UAAU;wBAC9B,MAAM,EAAE,MAAA,OAAO,CAAC,MAAM,mCAAI,EAAE;qBAC7B;oBACD,4BAAY,CAAC,iBAAiB;oBAC9B,4BAAY;oBACZ,mCAAoB;oBACpB,GAAG,CAAC,MAAA,OAAO,CAAC,SAAS,mCAAI,EAAE,CAAC;iBAC7B;gBACD,OAAO,EAAE,CAAC,mCAAoB,EAAE,4BAAY,CAAC;aAC9C,CAAC;SACH;QAED,IAAI,OAAO,CAAC,QAAQ,EAAE;YACpB,OAAO;gBACL,MAAM,EAAE,IAAI;gBACZ,MAAM,EAAE,aAAW;gBACnB,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,SAAS,EAAE;oBACT;wBACE,OAAO,EAAE,qBAAS,CAAC,aAAa;wBAChC,QAAQ,EAAE,OAAO,CAAC,QAAQ;wBAC1B,MAAM,EAAE,MAAA,OAAO,CAAC,MAAM,mCAAI,EAAE;qBAC7B;oBACD,4BAAY,CAAC,iBAAiB;oBAC9B,4BAAY;oBACZ,mCAAoB;oBACpB,GAAG,CAAC,MAAA,OAAO,CAAC,SAAS,mCAAI,EAAE,CAAC;iBAC7B;gBACD,OAAO,EAAE,CAAC,mCAAoB,EAAE,4BAAY,CAAC;aAC9C,CAAC;SACH;QAED,IAAI,OAAO,CAAC,QAAQ,EAAE;YACpB,OAAO;gBACL,MAAM,EAAE,IAAI;gBACZ,MAAM,EAAE,aAAW;gBACnB,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,SAAS,EAAE;oBACT;wBACE,OAAO,EAAE,qBAAS,CAAC,aAAa;wBAChC,QAAQ,EAAE,OAAO,CAAC,QAAQ;wBAC1B,MAAM,EAAE,MAAA,OAAO,CAAC,MAAM,mCAAI,EAAE;qBAC7B;oBACD,4BAAY,CAAC,iBAAiB;oBAC9B,4BAAY;oBACZ,mCAAoB;oBACpB,GAAG,CAAC,MAAA,OAAO,CAAC,SAAS,mCAAI,EAAE,CAAC;iBAC7B;gBACD,OAAO,EAAE,CAAC,mCAAoB,EAAE,4BAAY,CAAC;aAC9C,CAAC;SACH;QAED,MAAM,IAAI,UAAU,CAAC,iFAAiF,CAAC,CAAC;IAC1G,CAAC;CACF,CAAA;AAzEY,WAAW;IADvB,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,WAAW,CAyEvB;AAzEY,kCAAW"} |
| import { OnModuleDestroy, Provider } from '@nestjs/common'; | ||
| import { RedisConnection } from './interfaces/options.interface'; | ||
| export declare class RedisService implements OnModuleDestroy { | ||
| readonly connection: RedisConnection; | ||
| static connectionFactory: Provider<Promise<RedisConnection>>; | ||
| constructor(connection: RedisConnection); | ||
| onModuleDestroy(): Promise<void>; | ||
| } |
| "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 __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.RedisService = void 0; | ||
| const common_1 = require("@nestjs/common"); | ||
| const ioredis_1 = __importDefault(require("ioredis")); | ||
| const constants_1 = require("./constants"); | ||
| let RedisService = class RedisService { | ||
| constructor(connection) { | ||
| this.connection = connection; | ||
| } | ||
| async onModuleDestroy() { | ||
| return this.connection.disconnect(); | ||
| } | ||
| }; | ||
| RedisService.connectionFactory = { | ||
| inject: [ | ||
| { | ||
| token: constants_1.Providers.REDIS_OPTIONS, | ||
| optional: false, | ||
| }, | ||
| ], | ||
| provide: constants_1.Providers.REDIS_CONNECTION, | ||
| useFactory: async (config) => { | ||
| return new ioredis_1.default(config.port, config.host, config.ioredis); | ||
| }, | ||
| }; | ||
| RedisService = __decorate([ | ||
| (0, common_1.Injectable)(), | ||
| __param(0, (0, common_1.Inject)(constants_1.Providers.REDIS_CONNECTION)), | ||
| __metadata("design:paramtypes", [Object]) | ||
| ], RedisService); | ||
| exports.RedisService = RedisService; | ||
| //# sourceMappingURL=redis.service.js.map |
| {"version":3,"file":"redis.service.js","sourceRoot":"","sources":["../src/redis.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,2CAA+E;AAC/E,sDAA8B;AAE9B,2CAAwC;AAIxC,IAAa,YAAY,GAAzB,MAAa,YAAY;IAcvB,YAAgE,UAA2B;QAA3B,eAAU,GAAV,UAAU,CAAiB;IAAG,CAAC;IAE/F,KAAK,CAAC,eAAe;QACnB,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC;IACtC,CAAC;CACF,CAAA;AAlBQ,8BAAiB,GAAuC;IAC7D,MAAM,EAAE;QACN;YACE,KAAK,EAAE,qBAAS,CAAC,aAAa;YAC9B,QAAQ,EAAE,KAAK;SAChB;KACF;IACD,OAAO,EAAE,qBAAS,CAAC,gBAAgB;IACnC,UAAU,EAAE,KAAK,EAAE,MAAoB,EAA4B,EAAE;QACnE,OAAO,IAAI,iBAAO,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IAC/D,CAAC;CACD,CAAA;AAZS,YAAY;IADxB,IAAA,mBAAU,GAAE;IAeE,WAAA,IAAA,eAAM,EAAC,qBAAS,CAAC,gBAAgB,CAAC,CAAA;;GAdpC,YAAY,CAmBxB;AAnBY,oCAAY"} |
Unpublished package
Supply chain riskPackage version was not found on the registry. It may exist on a different registry and need to be configured to pull from that registry.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Unpublished package
Supply chain riskPackage version was not found on the registry. It may exist on a different registry and need to be configured to pull from that registry.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
61826
210.4%0
-100%67
235%1230
373.08%264
363.16%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed