本文整理匯總了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;
});