A simple Node.js Express API with Redis caching for product management. This application demonstrates basic CRUD operations with Redis caching implementation.
- Redis Caching: Efficient data retrieval with TTL
- Express API: RESTful endpoints for product management
- Docker Integration: Easy Redis setup with Docker
- Error Handling: Comprehensive error management
- Cache Invalidation: Automatic cache clearing on updates
- Node.js (v14 or higher)
- Docker
- npm or yarn
git clone <repository-url>
cd redis-node-appnpm installdocker run --name my-redis -p 6379:6379 -d redisnode app.jsGET /products{
"1": { "id": 1, "name": "Laptop", "price": 999.99 },
"2": { "id": 2, "name": "Smartphone", "price": 499.99 }
}GET /products/:id| Parameter | Type | Description |
|---|---|---|
id |
string |
Product ID |
{
"id": 1,
"name": "Laptop",
"price": 999.99
}POST /products{
"name": "New Product",
"price": 199.99
}DELETE /products/:id/cache# View logs
docker logs my-redis
# Access Redis CLI
docker exec -it my-redis redis-cli
# List all keys
docker exec -it my-redis redis-cli KEYS *# Stop container
docker stop my-redis
# Remove container
docker rm my-redisredis-node-app/
├── index.js # Main application file
├── package.json # Dependencies
└── README.md # Documentation
The application handles various error scenarios:
- Redis connection errors
- Server errors (500)
- Not found errors (404)
- Invalid request errors
| Cache Type | TTL | Key Pattern |
|---|---|---|
| Single Product | 1 hour | product:{id} |
| All Products | 1 hour | all_products |
Note: Make sure to replace <repository-url> with your actual repository URL.