- Install and run Redis
- Run
npm install
- Run
npm run dev --port=3000
- Open http://127.0.0.1:3000 in your browser.
ALTERNATIVE: docker-compose up -d
Redis provides a set of flexible commands that can be really helpful in solving our real-world problems. For instancce, the SET
command has options such as NX (only set the key if it does not already exist), hence we do not need to check if it already exists and this means running fewer commands. Here I set a key with an expire time, if it does not exist, and use the INCR
command to increase its value by one. This command returns the new value and the incomming request gets blocked if it exceeded the defined limitation.
- Blocks the user after exceeding limitations
- Each endpoint has a specified limitation
- Users are known by their IP addresses