Skip to content

Commit

Permalink
rate limiting
Browse files Browse the repository at this point in the history
  • Loading branch information
ewansheldon committed Jan 8, 2025
1 parent d1704b6 commit 7a090bf
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/rate.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ const redis = createClient({
redis.on('error', err => console.log('Redis Client Error', err));

const limited = async ip => {
return false;
const key = `rateLimit:${ip}`
const reqLimit = 100;
if (!redis.isReady) await redis.connect();
const visits = await redis.INCR(key);
if (visits === 1) await redis.EXPIRE(key, 60);
await redis.disconnect();
return false;
return visits > reqLimit;
}

Expand Down

0 comments on commit 7a090bf

Please sign in to comment.