This is a Memcached module for Nest.
$ npm i --save @nestcloud/memcached memcached
import { Module } from '@nestjs/common';
import { MemcachedModule } from '@nestcloud/memcached';
@Module({
imports: [
MemcachedModule.register({
uri: [
'192.168.0.102:11211',
'192.168.0.103:11211',
'192.168.0.104:11211'
],
retries: 3
})
],
})
export class ApplicationModule {}
If you use @nestcloud/boot module.
import { Module } from '@nestjs/common';
import { MemcachedModule } from '@nestcloud/memcached';
import { BootModule } from '@nestcloud/boot';
import { NEST_BOOT } from '@nestcloud/common';
@Module({
imports: [
BootModule.register(__dirname, 'bootstrap.yml'),
MemcachedModule.register({dependencies: [NEST_BOOT]})
],
})
export class ApplicationModule {}
memcached:
uri: ['192.168.0.102:11211', '192.168.0.103:11211', '192.168.0.104:11211'],
retries: 3
If you use @nestcloud/consul-config module.
import { Module } from '@nestjs/common';
import { MemcachedModule } from '@nestcloud/memcached';
import { ConsulModule } from '@nestcloud/consul';
import { ConsulConfigModule } from '@nestcloud/consul-config';
import { NEST_CONSUL_CONFIG } from '@nestcloud/common';
@Module({
imports: [
ConsulModule.register({/* ignore */}),
ConsulConfigModule.register({/* ignore */}),
MemcachedModule.register({dependencies: [NEST_CONSUL_CONFIG]})
],
})
export class ApplicationModule {}
memcached:
uri: ['192.168.0.102:11211', '192.168.0.103:11211', '192.168.0.104:11211'],
retries: 3
import { Component } from '@nestjs/common';
import { InjectMemcachedClient, Memcached } from '@nestcloud/memcached';
@Component()
export class TestService {
constructor(@InjectMemcachedClient() private readonly memClient: Memcached) {}
async addValue(key: string, value: string): void {
await this.memClient.add(key, value);
}
async deleteValue(key: string): void {
await this.memClient.del(key);
}
}
NestCloud is an MIT-licensed open source project.
- Author - NestCloud
NestCloud is MIT licensed.