本文整理汇总了TypeScript中ratelimiter.get函数的典型用法代码示例。如果您正苦于以下问题:TypeScript get函数的具体用法?TypeScript get怎么用?TypeScript get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: detectBriefInterval
// 短い期間の方のリミット
function detectBriefInterval(): void {
const minIntervalLimiter = new Limiter({
id: `${context.user.id}:${endpoint.name}:for-detect-brief-interval`,
duration: endpoint.minInterval,
max: 1,
db: limiterDB
});
minIntervalLimiter.get((limitErr, limit) => {
if (limitErr !== null) {
return reply({
error: 'something-happened'
}).code(500);
} else if (limit.remaining === 0) {
return reply({
error: 'brief-interval-detected'
}).code(429);
} else {
if (endpoint.hasOwnProperty('limitDuration') && endpoint.hasOwnProperty('limitMax')) {
rateLimit();
} else {
call();
}
}
});
}
示例2: min
// Short-term limit
function min() {
const minIntervalLimiter = new Limiter({
id: `${user._id}:${key}:min`,
duration: limitation.minInterval,
max: 1,
db: limiterDB
});
minIntervalLimiter.get((err, info) => {
if (err) {
return reject('ERR');
}
log(`@${getAcct(user)} ${endpoint.name} min remaining: ${info.remaining}`);
if (info.remaining === 0) {
reject('BRIEF_REQUEST_INTERVAL');
} else {
if (hasLongTermLimit) {
max();
} else {
ok();
}
}
});
}
示例3: max
// Long term limit
function max(): void {
const limiter = new Limiter({
id: `${ctx.user._id}:${limitKey}`,
duration: endpoint.limitDuration,
max: endpoint.limitMax,
db: limiterDB
});
limiter.get((limitErr, limit) => {
if (limitErr) {
reject('ERR');
} else if (limit.remaining === 0) {
reject('RATE_LIMIT_EXCEEDED');
} else {
ok();
}
});
}
示例4: rateLimit
// 長い期間の方のリミット
function rateLimit(): void {
const limiter = new Limiter({
id: `${context.user.id}:${limitKey}`,
duration: endpoint.limitDuration,
max: endpoint.limitMax,
db: limiterDB
});
limiter.get((limitErr, limit) => {
if (limitErr !== null) {
return reply({
error: 'something-happened'
}).code(500);
} else if (limit.remaining === 0) {
return reply({
error: 'rate-limit-exceeded'
}).code(429);
} else {
call();
}
});
}
示例5: max
// Long term limit
function max() {
const limiter = new Limiter({
id: `${user._id}:${key}`,
duration: limitation.duration,
max: limitation.max,
db: limiterDB
});
limiter.get((err, info) => {
if (err) {
return reject('ERR');
}
log(`@${getAcct(user)} ${endpoint.name} max remaining: ${info.remaining}`);
if (info.remaining === 0) {
reject('RATE_LIMIT_EXCEEDED');
} else {
ok();
}
});
}
示例6: min
// Short-term limit
function min(): void {
const minIntervalLimiter = new Limiter({
id: `${ctx.user._id}:${limitKey}:min`,
duration: endpoint.minInterval,
max: 1,
db: limiterDB
});
minIntervalLimiter.get((limitErr, limit) => {
if (limitErr) {
reject('ERR');
} else if (limit.remaining === 0) {
reject('BRIEF_REQUEST_INTERVAL');
} else {
if (hasRateLimit) {
max();
} else {
ok();
}
}
});
}
示例7: Limiter
import * as redis from 'redis';
import * as Limiter from 'ratelimiter';
declare let id: string;
declare let db: redis.RedisClient;
let limit = new Limiter({ id: id, db: db });
const str: string = limit.inspect();
limit.get((err, limit): void => {
const total: number = limit.total;
const remaining: number = limit.remaining;
const reset: number = limit.reset;
});