Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/svtslv/nestjs-ioredis
IORedis module for Nest
https://github.com/svtslv/nestjs-ioredis
ioredis nest nestjs redis
Last synced: 6 days ago
JSON representation
IORedis module for Nest
- Host: GitHub
- URL: https://github.com/svtslv/nestjs-ioredis
- Owner: svtslv
- Created: 2020-03-11T20:01:10.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-06-18T01:17:14.000Z (5 months ago)
- Last Synced: 2024-09-22T21:21:31.475Z (about 2 months ago)
- Topics: ioredis, nest, nestjs, redis
- Language: TypeScript
- Homepage:
- Size: 1.5 MB
- Stars: 27
- Watchers: 4
- Forks: 3
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NestJS IORedis
## Table of Contents
- [Description](#description)
- [Installation](#installation)
- [Examples](#examples)
- [License](#license)## Description
Integrates IORedis with Nest## Installation
```bash
npm install @svtslv/nestjs-ioredis ioredis
``````bash
npm install -D @types/ioredis
```You can also use the interactive CLI
```sh
npx nestjs-modules
```## Examples
```sh
docker run -p 6379:6379 redis
```### RedisModule.forRoot(options, connection?)
```ts
import { Module } from '@nestjs/common';
import { RedisModule } from '@svtslv/nestjs-ioredis';
import { AppController } from './app.controller';@Module({
imports: [
RedisModule.forRoot({
config: {
// host: 'localhost',
// port: 6379,
url: 'redis://localhost:6379',
},
}),
],
controllers: [AppController],
})
export class AppModule {}
```### RedisModule.forRootAsync(options, connection?)
```ts
import { Module } from '@nestjs/common';
import { RedisModule } from '@svtslv/nestjs-ioredis';
import { AppController } from './app.controller';@Module({
imports: [
RedisModule.forRootAsync({
useFactory: () => ({
config: {
// host: 'localhost',
// port: 6379,
url: 'redis://localhost:6379',
},
}),
}),
],
controllers: [AppController],
})
export class AppModule {}
```### InjectRedis(connection?)
```ts
import { Controller, Get, } from '@nestjs/common';
import { InjectRedis, Redis } from '@svtslv/nestjs-ioredis';@Controller()
export class AppController {
constructor(
@InjectRedis() private readonly redis: Redis,
) {}@Get()
async getHello() {
await this.redis.set('key', 'Redis data!');
const redisData = await this.redis.get("key");
return { redisData };
}
}
```## License
MIT