nestjs-redis-connection
v1.0.0
Published
redis connection module baseed on node-redis && @nestjs/config
Downloads
1
Maintainers
Readme
nestjs-redis
config redis by nestjs/config
- based on node-redis connection options
RedisClientOptions
RedisConfig: [
{
//redis[s]://[[username][:password]@][host][:port][/db-number]:
url: 'redis://127.0.0.1:6379',
name: 'test',
},
],
- register redis module by static function register
RedisConnectionModule.register({
configKey: 'RedisConfig',
errorHandler: (error) => {
// err handler
}
}),
- get redis client by redisConnectionService
@Injectable()
export class UserService {
@Inject()
private readonly redisConnectionService: RedisConnectionService;
async getcache() {
const redisClient = this.redisConnectionService.getClient('test');
return await redisClient.get('xx')
}
}
- enable nestjs shutdownhooks, so that the destory hooks of redis connection module can exe .
app.enableShutdownHooks();
problems
- if u use webpack bundle you project, plz compile node-redis by babel like this.
rules: [
{
test: /\.m?js$/,
include: [
path.join(__dirname, 'node_modules/redis'),
path.join(__dirname, 'node_modules/@redis'),
],
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
},
]