1. Redis for Authentication (Session Caching)
Why use Redis?
Traditional databases (SQL) are slow for checking sessions on every request. Redis stores active sessions in RAM, allowing for sub-millisecond validation.
Demo Logic: When you login, we generate a JWT and store it in Redis with a 15-second TTL (Time To Live). When the time is up, Redis automatically deletes the key, instantly revoking access.
2. Redis for Rate Limiting
How it works
We use Redis Atomic Counters (`INCR`). Every time you hit the API, we increment a counter for your IP address.
If the counter exceeds 5 requests within a 10-second window, the backend rejects the request. Redis handles the expiration of this window automatically.
Try to spam the button below. Redis will block you after 5 requests in 10 seconds.