A simple Node.js Express application for testing Azure Redis Cache connectivity and basic operations.
For easy deployment and cleanup, use the provided Terraform-based scripts:
# Optional: Copy and customize variables
cp terraform.tfvars.example terraform.tfvars
# Deploy infrastructure and application
./deploy.shThis script will:
- Initialize Terraform
- Create an Azure resource group using Terraform
- Create a Redis Cache instance (Basic SKU)
- Create an App Service Plan and Web App
- Configure environment variables automatically
- Deploy the application using
az webapp up
./cleanup.shThis script removes all Azure resources created by Terraform using terraform destroy.
- Health check endpoint to verify Redis connectivity
- Set and get key-value pairs in Redis
- Proper error handling and logging
- Environment variable configuration
- Graceful shutdown handling
- Node.js >= 20.0.0
- Terraform (>= 1.0)
- Azure CLI logged in (
az login) - Azure subscription with sufficient permissions
- Clone the repository:
git clone <repository-url>
cd azure-redis-cache-test- Navigate to the app directory and install dependencies:
cd app
npm installCustomize deployment by copying and editing the variables file:
cp terraform.tfvars.example terraform.tfvarsAvailable variables:
resource_group_name: Name of the Azure resource group (default: "redis-cache-test-rg")location: Azure region (default: "australiasoutheast")redis_name: Base name for Redis cache (default: "redis-cache-test")app_service_plan_name: App Service Plan name (default: "redis-cache-test-plan")app_name: Base name for web app (default: "redis-cache-test-app")tags: Resource tags
Terraform automatically configures these environment variables:
REDIS_URL: Azure Redis Cache URLREDIS_ACCESS_KEY: Redis access keyPORT: Server port (defaults to 3000)
cd app
npm startGET /- Application status and Redis connection infoGET /health- Health check with Redis ping testGET /set/:key/:value- Set a key-value pair in RedisGET /get/:key- Get a value from Redis by key
# Check application status
curl http://localhost:3000/
# Health check
curl http://localhost:3000/health
# Set a value
curl http://localhost:3000/set/mykey/myvalue
# Get a value
curl http://localhost:3000/get/mykeyThe deployment uses Terraform for infrastructure management:
-
Initialize Terraform:
terraform init
-
Plan deployment:
terraform plan
-
Apply infrastructure:
terraform apply
-
Deploy application:
cd app az webapp up --name $(terraform output -raw app_service_name) \ --resource-group $(terraform output -raw resource_group_name) \ --plan $(terraform output -raw app_service_plan_name) \ --runtime "NODE:22-lts" --sku F1
az webapp config appsettings set \
--name your-app-name \
--resource-group your-resource-group \
--settings REDIS_URL="your-redis-url" REDIS_ACCESS_KEY="your-key"azure-redis-cache-test/
├── app/
│ ├── package.json # Node.js dependencies
│ ├── package-lock.json # Locked dependency versions
│ └── server.js # Main application file
├── main.tf # Main Terraform configuration
├── variables.tf # Terraform variables
├── outputs.tf # Terraform outputs
├── terraform.tfvars.example # Example Terraform variables
├── deploy.sh # Terraform-based deployment script
├── cleanup.sh # Terraform destroy script
├── .gitignore # Git ignore rules
└── README.md # This file
The Terraform configuration creates:
- Resource Group: Container for all resources
- Redis Cache: Basic SKU with C0 capacity
- App Service Plan: Linux-based F1 (Free) tier
- Linux Web App: Node.js 22-lts runtime
- App Settings: Automatic Redis connection configuration
The application includes comprehensive error handling:
- Redis connection failures are logged and handled gracefully
- API endpoints return appropriate HTTP status codes
- Health check endpoint indicates Redis connectivity status
- Graceful shutdown on SIGTERM
- No hardcoded credentials - uses environment variables
- TLS connection to Redis enabled
- Proper error messages without exposing sensitive information
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
MIT License