nest-memcached
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Nest Logo

Description

This is a Memcached module for Nest.

Installation

$ npm i --save nest-memcached memcached

Quick Start

Import Module

import { Module } from '@nestjs/common';
import { MemcachedModule } from 'nest-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 nest-boot module.

import { Module } from '@nestjs/common';
import { MemcachedModule } from 'nest-memcached';
import { BootModule } from 'nest-boot';
import { NEST_BOOT } from 'nest-common';
 
@Module({
  imports: [
      BootModule.register(__dirname, 'bootstrap.yml'),
      MemcachedModule.register({dependencies: [NEST_BOOT]})
  ],
})
export class ApplicationModule {}
bootstrap.yml
memcached:
  uri: ['192.168.0.102:11211', '192.168.0.103:11211', '192.168.0.104:11211'],
  retries: 3

If you use nest-consul-config module.

import { Module } from '@nestjs/common';
import { MemcachedModule } from 'nest-memcached';
import { ConsulModule } from 'nest-consul';
import { ConsulConfigModule } from 'nest-consul-config';
import { NEST_CONSUL_CONFIG } from 'nest-common';
 
@Module({
  imports: [
      ConsulModule.register({/* ignore */}),
      ConsulConfigModule.register({/* ignore */}),
      MemcachedModule.register({dependencies: [NEST_CONSUL_CONFIG]})
  ],
})
export class ApplicationModule {}
config in consul kv
memcached:
  uri: ['192.168.0.102:11211', '192.168.0.103:11211', '192.168.0.104:11211'],
  retries: 3

Memcached Client Injection

import { Component } from '@nestjs/common';
import { InjectMemcachedClient, Memcached } from 'nest-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);
  }
}

Support

NestCloud is an MIT-licensed open source project.

Stay in touch

License

NestCloud is MIT licensed.

Readme

Keywords

none

Package Sidebar

Install

npm i nest-memcached

Weekly Downloads

17

Version

1.0.1

License

MIT

Unpacked Size

60.6 kB

Total Files

25

Last publish

Collaborators

  • zfeng