https://github.com/bpcloud/middleware-redis
redis middleware of bpframework
https://github.com/bpcloud/middleware-redis
Last synced: about 1 month ago
JSON representation
redis middleware of bpframework
- Host: GitHub
- URL: https://github.com/bpcloud/middleware-redis
- Owner: bpcloud
- License: mit
- Created: 2021-04-09T11:30:03.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2025-01-20T08:29:36.000Z (4 months ago)
- Last Synced: 2025-04-09T21:08:52.119Z (about 1 month ago)
- Language: TypeScript
- Size: 55.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# redis middleware in bpframework.
### Middleware specification
https://github.com/bpcloud/middleware
### usage
#### Setup.
```js
import { Application } from 'bpframework';
import * as middleware_redis from '@bpframework/middleware-redis';Application.use(middleware_redis.middleware)
Application.runKoa(...);
```#### Config.
```properties
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.
```js
@Service()
class Configure {
@Bean()
redisTemplate(): RedisTemplate {
return new RedisTemplate("spring.redis");
}
}
```#### Use.
```js
@Service()
class RedisService {@Autowired("redisTemplate")
redisTemplate: RedisTemplate;async foo(): Promise {
return await this.redisTemplate.keys("*");
}
}
```
```