Redis
安装#
$ npm i @tiejs/redis
配置#
// config.ts
export const redis = {
host: '1.14.165.196',
port: 6379,
}
使用#
import { Controller, Get } from '@tiejs/controller'
import { Redis } from 'ioredis'
import { InjectRedisClient } from '@tiejs/redis'
import { UserService } from './user.service'
@Controller()
export class UserController {
constructor(private userService: UserService, @InjectRedisClient() private redis: Redis) {}
@Get('/')
async index() {
return {
hello: 'hello world',
greeting: await this.redis.get('greeting'),
}
}
}