{"_rev":"6-06e97641b867907d112e589445552914","time":{"created":"2023-08-21T06:34:28.987Z","0.0.1":"2023-08-21T03:08:01.236Z","modified":"2023-08-21T06:34:29.583Z","1.0.0":"2023-08-21T03:44:29.716Z","1.0.1":"2023-08-21T03:59:02.894Z","1.0.2":"2023-08-21T05:48:08.660Z","1.0.5":"2023-08-21T06:34:29.309Z"},"_id":"@ashu_guo/nest-redis","name":"@ashu_guo/nest-redis","dist-tags":{"latest":"1.0.5"},"versions":{"1.0.5":{"name":"@ashu_guo/nest-redis","version":"1.0.5","description":"ioredis utilities module for nestjs framework","author":{"name":"ashu_guo"},"license":"MIT","scripts":{"format":"prettier --write \"**/*.ts\"","lint":"eslint \"lib/**/*.ts\" --fix","test":"jest --config=jest.json","test:watch":"jest --config=jest.json --watch","test:coverage":"jest --config=jest.json --coverage --coverageDirectory=coverage","build":"rm -rf dist && tsc -p tsconfig.json","precommit":"lint-staged","prepublish:npm":"npm run build","publish:npm":"npm publish --access public","prerelease":"npm run build","release":"release-it","prepare":"husky install"},"peerDependencies":{"@nestjs/common":"^8.0.0 || ^9.0.0 || ^10.0.0"},"devDependencies":{"@commitlint/cli":"17.7.1","@commitlint/config-angular":"17.7.0","@nestjs/common":"10.1.3","@nestjs/core":"10.1.3","@nestjs/testing":"10.1.3","@types/jest":"29.5.3","@types/node":"18.17.5","@typescript-eslint/eslint-plugin":"6.4.0","@typescript-eslint/parser":"6.4.0","eslint":"8.47.0","eslint-plugin-import":"2.28.0","husky":"8.0.3","jest":"29.6.2","lint-staged":"14.0.0","prettier":"3.0.2","reflect-metadata":"0.1.13","release-it":"16.1.5","ts-jest":"29.1.1","typescript":"5.1.6"},"keywords":["nestjs","redis"],"dependencies":{"ioredis":"^5.3.2"},"lint-staged":{"**/*.{ts,json}":[]},"repository":{"type":"git","url":"git+https://github.com/aShu-guo/nest-redis.git"},"types":"./index.d.ts","gitHead":"ed1d3d0dc411a63b69a12852b956f2ee29f86b53","bugs":{"url":"https://github.com/aShu-guo/nest-redis/issues"},"homepage":"https://github.com/aShu-guo/nest-redis#readme","_id":"@ashu_guo/nest-redis@1.0.5","_nodeVersion":"16.15.1","_npmVersion":"8.11.0","dist":{"integrity":"sha512-gqOlT030XeY3veGETwmRSBYNaVxuUcY2Wak+2wcX1AKDF/yRvUF44jl+VYjMzNNJqDeGZWNCGWL/N4JymogQ7w==","shasum":"bfe983e2d15c1857f3eeb52c6499e87ca5b57867","tarball":"https://registry.npmjs.org/@ashu_guo/nest-redis/-/nest-redis-1.0.5.tgz","fileCount":31,"unpackedSize":16990,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGmEMo/qLQN8veSMlA2B1kRE7/CD59VRf5x+Jod92RkSAiEAnRH9Nw88tdCeKiakqSb20nVfEMzKIr6pvmnzRUj36tM="}]},"_npmUser":{"name":"ashu_guo","email":"guochengli97@163.com"},"directories":{},"maintainers":[{"name":"ashu_guo","email":"guochengli97@163.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/nest-redis_1.0.5_1692599669050_0.7301099526621604"},"_hasShrinkwrap":false}},"maintainers":[{"name":"ashu_guo","email":"guochengli97@163.com"}],"description":"ioredis utilities module for nestjs framework","homepage":"https://github.com/aShu-guo/nest-redis#readme","keywords":["nestjs","redis"],"repository":{"type":"git","url":"git+https://github.com/aShu-guo/nest-redis.git"},"author":{"name":"ashu_guo"},"bugs":{"url":"https://github.com/aShu-guo/nest-redis/issues"},"license":"MIT","readme":"<p align=\"center\">\n  <a href=\"http://nestjs.com/\" target=\"blank\"><img src=\"https://nestjs.com/img/logo-small.svg\" width=\"120\" alt=\"Nest Logo\" /></a>\n</p>\n\n  <p align=\"center\">A progressive <a href=\"http://nodejs.org\" target=\"blank\">Node.js</a> framework for building efficient and scalable server-side applications.</p>\n    <p align=\"center\">\n\n## Description\n\nioredis utilities module for nestjs framework\n\n## Installation\n\n```bash\n$ npm i --save @ashu_guo/nest-redis\n```\n\n## Usage\n\nImport `RedisModule`:\n\n```typescript\nimport {RedisModule} from '@ashu_guo/nest-redis';\n\n@Module({\n    imports: [RedisModule.register({\n        host: 'localhost',\n        port: 6379,\n        username: 'xxxxx',\n        password: '*****',\n    })],\n    providers: [...],\n})\nexport class UsersModule {\n}\n```\n\nInject `RedisClient`:\n\n```typescript\nimport {InjectRedisClient, RedisClient} from '@ashu_guo/nest-redis';\n\n@Injectable()\nexport class UsersService {\n    constructor(@InjectRedisClient() private readonly redisClient: RedisClient) {\n    }\n}\n```\n\n## Async options\n\nQuite often you might want to asynchronously pass your module options instead of passing them beforehand. In such case,\nuse `registerAsync()` method, that provides a couple of various ways to deal with async data.\n\n**1. Use factory**\n\n```typescript\n@Module({\n    imports: [\n        RedisModule.registerAsync({\n            useFactory: () => ({\n                host: 'localhost',\n                port: 6379,\n                username: 'xxxxx',\n                password: '*****',\n            })\n        })\n    ]\n})\n\nexport class AppModule {\n}\n\n```\n\nObviously, our factory behaves like every other one (might be `async` and is able to inject dependencies\nthrough `inject`).\n\n```typescript\nRedisModule.registerAsync({\n    imports: [ConfigModule],\n    useFactory: async (configService: ConfigService) => ({\n        host: configService.get<string>('REDIS_HOST'),\n        port: configService.get<number>('REDIS_PORT'),\n        username: configService.get<string>('REDIS_USERNAME'),\n        password: configService.get<string>('REDIS_PASSWORD'),\n    }),\n    inject: [ConfigService],\n})\n```\n\n**2. Use class**\n\n```typescript\nRedisModule.registerAsync({\n    useClass: RedisConfigService\n});\n```\n\nAbove construction will instantiate `RedisConfigService` inside `RedisModule` and will leverage it to create options\nobject.\n\n```typescript\nimport {RedisOptionsFactory} from '@ashu_guo/nest-redis';\nimport {RedisOptions} from 'ioredis';\n\nexport class RedisConfigService implements RedisOptionsFactory {\n    createRedisOptions(): RedisOptions {\n        return {\n            host: 'localhost',\n            port: 6379,\n            username: 'xxxxxx',\n            password: '******',\n        };\n    }\n}\n```\n\n**3. Use existing**\n\n```typescript\nRedisModule.registerAsync({\n    imports: [ConfigModule],\n    useExisting: ConfigService,\n})\n```\n\nIt works the same as `useClass` with one critical difference - `RedisModule` will lookup imported modules to reuse\nalready created `ConfigService`, instead of instantiating it on its own.\n\n## Used By\n\n- [rbac-admin](https://github.com/aShu-guo/rbac-admin)\n\n## API Spec\n\nThe `RedisModule` takes an [`options`](https://ioredis.readthedocs.io/en/latest/API/#Redis) object:\n\n## License\n\nNest is [MIT licensed](LICENSE).\n","readmeFilename":"README.md"}