@bpframework/middleware-redis
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

redis middleware in bpframework.

Middleware specification

https://github.com/bpcloud/middleware

usage

Setup.

import { Application } from 'bpframework';
import * as middleware_redis from '@bpframework/middleware-redis';

Application.use(middleware_i18n.middleware)
Application.runKoa(...);

Config.

spring.redis:
  database: 0     # Redis数据库索引(默认为0)
  host: 127.0.0.1 # 单机模式host (优先使用此配置).
  port: 6379      # 单机模式port.
  cluster:        # 集群模式主机信息.
    nodes:          # Redis服务器地址列表
    - host: 127.0.0.1
      port: 6379
    - host: 127.0.0.1
      port: 6380
    - host: 127.0.0.1
      port: 6381
  password:       # Redis服务器连接密码(默认为空) 
  timeout: 0      # 连接超时时间(毫秒)
  default-ttl:           5    # 默认的ttl; 单位秒, 默认5分钟. (默认的过期时间对hash表无效, hash需单独设置) 
  default-ttl-tolerance: 10   # 单位秒; ttl时间增加这个抖动范围, 默认10秒

Define Bean.

@Service()
class Configure {
  @Bean()
  redisTemplate(): RedisTemplate {
    return new RedisTemplate("spring.redis");
  }
}

Use.

@Service()
class RedisService {

  @Autowired("redisTemplate")
  redisTemplate: RedisTemplate;

  async foo(): Promise<string[]> {
    return await this.redisTemplate.keys("*");
  }
}

Readme

Keywords

Package Sidebar

Install

npm i @bpframework/middleware-redis

Weekly Downloads

6

Version

0.0.5

License

MIT

Unpacked Size

60.2 kB

Total Files

23

Last publish

Collaborators

  • brainpoint