0.7.0 • Published 4 years ago

@sensejs/redis v0.7.0

Weekly downloads
26
License
ISC
Repository
-
Last release
4 years ago

@sensejs/redis

redis module for sensejs

The underlying of RedisModule uses ioredis

API

RedisModule: (options: RedisModuleOptions|RedisModuleOptions[]) => ModuleConstructor

create a redis module with options

option: RedisModuleOptions

redis module option

uri: String

redis connection str

name: String|Symbol

named redis for get specific redis

options: ioredis.Redis

ioredis option

InjectRedis: (name?: string | symbol) => ParameterDecorator

inject redis decorator

name: string | symbol

redis name

Usage

  • single redis
import {Controller} from '@sensejs/http';
import {RedisModule, InjectRedis} from '@sensejs/redis';
import Redis from 'ioredis';

const redisModule = RedisModule({uri: 'localhost'});

@Controller('/example')
class FooController {
  constructor(@InjectRedis() private redis: Redis.redis) {}

  exmaple() {
    return this.redis.get('key');
  }
}
  • multi redis
import {Controller} from '@sensejs/http';
import {RedisModule, InjectRedis} from '@sensejs/redis';
import Redis from 'ioredis';

const redisOption1 = {uri: 'localhost/1', name: 'redis1'};
const redisOption2 = {uri: 'localhost/2', name: 'redis2'};
const redisModule = RedisModule([redisOption1, redisOption2]);

@Controller('/example')
class FooController {
  constructor(
     @InjectRedis(redisOption1.name) private redis1: Redis.redis,
     @InjectRedis(redisOption2.name) private redis2: Redis.redis,
  ) {}

  async exmaple() {
    const redisValue1 = await this.redis1.get('key');
    const redisValue2 = await this.redis2.get('key');
  }
}

Tips

  • named redis should use named inject
import {Controller} from '@sensejs/http';
import {RedisModule, InjectRedis} from '@sensejs/redis';
import Redis from 'ioredis';

const redisModule = RedisModule({uri: 'localhost', name: 'named'});

@Controller('/example')
class FooController {
  constructor(
    // this works
    @InjectRedis('named') private redis1: Redis.redis,
    // this will error
    @InjectRedis() private redis2: Redis.redis,
  ) {}

  exmaple() {
    return this.redis.get('key');
  }
}
0.7.0

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.0

4 years ago

0.4.1

4 years ago

0.4.2

4 years ago

0.4.0

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.3.0-0

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.2.0-0

4 years ago

0.1.0

4 years ago

0.1.1

4 years ago

0.1.0-0

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago