Skip to content

存储配置

1) RedisStore

基于 ioredis,支持单机、哨兵、集群三种模式。

typescript
import { RedisStore } from 'throttled-nodejs';

const store = new RedisStore('redis://127.0.0.1:6379/0', {});

参数

参数类型默认值说明
serverstring"redis://localhost:6379/0"Redis 连接 URL
optionsobject{}连接选项

选项

选项类型说明
SOCKET_TIMEOUTnumberSocket 超时(毫秒)
passwordstringRedis 密码
usernamestringRedis ACL 用户名
sentinelsArray哨兵节点(自动从 URL 解析)
clusterNodesArray集群节点(自动从 URL 解析)

2) MemoryStore

具有 TTL 的 LRU 缓存。

typescript
import { MemoryStore } from 'throttled-nodejs';

const store = new MemoryStore({ MAX_SIZE: 10240 });

选项

选项类型默认值说明
MAX_SIZEnumber1024最大条目数,超出后 LRU 淘汰

MIT License — Port of throttled-py