UNPKG

request-limit

Version:

通过redis缓存实现token对url的访问频率控制

26 lines (22 loc) 506 B
'use strict' class MemoryStore { constructor() { this.store = {} } async get(hashKey) { if (!this.store[hashKey]) { return 0 } return this.store[hashKey] || 0 } async incrby(hashKey, value) { if (!this.store[hashKey]) { this.store[hashKey] = 0 } this.store[hashKey] += value } async del(hashKey) { delete this.store[hashKey] } } module.exports = MemoryStore