The cache

Redisopen in new window is a high-performance key-value database

Redis largely compensates for memcached key/value storage, and in some cases complements relational databases.

TIP

You need to install redisopen in new window , or have a valid redis address

Redis

  • Step 1: Install the Redis module package provided by Zerone
yarn add @zeronejs/redis
1
  • Step 2: Import RedisModule into the root module
import { RedisModule } from '@zeronejs/redis';
@Module({
    imports: [
        RedisModule.forRoot(), // uses defaults unless given configuration object
        // ... Other modules
    ]
})
export class AppModule {}
1
2
3
4
5
6
7
8
  • Step 3: Dependency injection where Redis is needed
import { Inject } from '@nestjs/common';
import { REDIS_CLIENT, Redis } from '@zeronejs/redis';

...
export class AppController {
    constructor(
        @Inject(REDIS_CLIENT) private readonly redisClient: Redis
    ) {}

    @Get()
    async getHello() {
        console.log(await this.redisClient.set('key', 'value'));
        console.log(await this.redisClient.get('key'));
        return 'hello';
    }
}
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17