{"id":"8aec8385e564bd20","repo":"nestjs/nest","slug":"not-initialized-please-call-the-listen-startal-8aec83","errorCode":null,"errorMessage":"Not initialized. Please call the \"listen\"/\"startAllMicroservices\" method before accessing the server.","messagePattern":"Not initialized\\. Please call the \"listen\"/\"startAllMicroservices\" method before accessing the server\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/microservices/server/server-redis.ts","lineNumber":281,"sourceCode":"    if (this.isManuallyClosed) {\n      return undefined;\n    }\n    if (!this.getOptionsProp(this.options, 'retryAttempts')) {\n      this.logger.error(\n        'Redis connection closed and retry attempts not specified',\n      );\n      return;\n    }\n    if (times > this.getOptionsProp(this.options, 'retryAttempts', 0)) {\n      this.logger.error(`Retry time exhausted`);\n      return;\n    }\n    return this.getOptionsProp(this.options, 'retryDelay', 5000);\n  }\n\n  public unwrap<T>(): T {\n    if (!this.pubClient || !this.subClient) {\n      throw new Error(\n        'Not initialized. Please call the \"listen\"/\"startAllMicroservices\" method before accessing the server.',\n      );\n    }\n    return [this.pubClient, this.subClient] as T;\n  }\n\n  public on<\n    EventKey extends keyof RedisEvents = keyof RedisEvents,\n    EventCallback extends RedisEvents[EventKey] = RedisEvents[EventKey],\n  >(event: EventKey, callback: EventCallback) {\n    if (this.subClient && this.pubClient) {\n      this.subClient.on(event, (...args: [any]) => callback('sub', ...args));\n      this.pubClient.on(event, (...args: [any]) => callback('pub', ...args));\n    } else {\n      this.pendingEventListeners.push({ event, callback });\n    }\n  }\n}","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/nestjs/nest/blob/6ec0e2783d15290732447f304d8549b591b9749e/packages/microservices/server/server-redis.ts#L263-L299","documentation":"Error \"Not initialized. Please call the \"listen\"/\"startAllMicroservices\" method before accessing the server.\" thrown in nestjs/nest.","triggerScenarios":"Thrown at packages/microservices/server/server-redis.ts:281 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Call app.listen() or app.startAllMicroservices() before accessing the Redis server instance.","Await listen() so the Redis connection is established before any access."],"exampleFix":"const app = await NestFactory.createMicroservice(AppModule, opts);\nawait app.listen();\nconst server = app.get(ServerRedis);","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"6ec0e2783d15290732447f304d8549b591b9749e","analyzedAt":"2026-08-03T17:42:23.673Z","schemaVersion":2}