redis
const redis = require('redis');
const client = redis.createClient();
client.setex('my-key', 300, 'my-value'); // Cache for 5 minutes
client.get('my-key', (err, reply) => {
if (err) { /* handle error */ }
console.log(reply); // 'my-value'
});
client.del('my-key'); // Delete the cacheconst redis = require('redis');
const client = redis.createClient();
client.incr('rate-limit:user-a', (err, reply) => {
if (err) { /* handle error */ }
if (reply > 10) { // Limit exceeded
console.log('Rate limit exceeded.');
}
});