Redis is an open source, in-memory data structure store used as a database, cache, message broker, and streaming engine.
You can to use gadin-redis package easily and setup it.
npm install gadin-redis
wait for the installation to finish.
You've added below code in your root module:
@Module({
imports: [
RedisModule.forRoot({
credentials: {
host: 'host',
port: 6379,
username:'user',
password:'pass'
}
})
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {
}
The username and password are optional.
You've to inject RedisClient in your service and use redis methods like below:
export class AppService{
constructor(@Inject(REDIS) private redis: RedisClient) {
}
async test() {
await this.redis.set("key", "value")
}
}
Import RedisClinet and REDIS from the gadin-redis