A simple HTTP service that maintains counters identified by unique URLs.
- Docker
- Python 3.12+
- pip
- Create a Python virtual environment and activate it:
<!-- validate:step id="setup_venv" -->
python -m venv venv
source venv/bin/activate
- Install Python dependencies:
<!-- validate:step id="install_deps" depends_on="setup_venv" -->
pip install -r requirements.txt
The service uses Docker to run Redis with persistent storage. Use the provided script to start all services:
<!-- validate:step id="start_services" depends_on="install_deps" background=true validate_port="6379,5000" -->
./start-services.sh
This will:
- Create a Docker volume for Redis data persistence
- Start Redis in a Docker container
- Start the Flask application
To stop all services and clean up, press Ctrl+C or run:
<!-- validate:cleanup -->
./start-services.sh cleanup
The test suite includes integration tests with Redis. To run the tests:
<!-- validate:step id="run_tests" depends_on="install_deps" expected_output="test session starts" -->
pytest -v tests/
The tests will:
- Start a separate Redis container for testing
- Run all test cases including:
- Basic counter operations
- Concurrent increment testing
- Health and status endpoint verification
- Automatically clean up the test container
Send a GET request to /counter/<counter_id>
to increment the counter:
<!-- validate:step id="test_increment" depends_on="start_services" expected_output="1" -->
curl http://localhost:5000/counter/my-counter
To get the current value without incrementing:
<!-- validate:step id="test_value" depends_on="test_increment" expected_output="1" -->
curl http://localhost:5000/counter/my-counter/value
Check service health:
<!-- validate:step id="test_health" depends_on="start_services" expected_output="healthy" -->
curl http://localhost:5000/health
Get detailed service status:
<!-- validate:step id="test_status" depends_on="start_services" expected_output="redis_connected" -->
curl http://localhost:5000/status
View all counters and their values in real-time:
<!-- validate:step id="test_dashboard" depends_on="start_services" validate_url="http://localhost:5000/dashboard" expected_status="200" -->
http://localhost:5000/dashboard
The dashboard provides:
- Live counter values with updates every second
- Total number of counters and increments
- Updates per second monitoring
- Timestamp of last update for each counter
- Sound notifications for counter updates (toggle with 🔔/🔕 button)
Each counter_id creates a unique counter. You can use any string as your counter_id!
The service can be configured using environment variables:
REDIS_HOST
: Redis server host (default: localhost)REDIS_PORT
: Redis server port (default: 6379)
Counter data is persisted in a Docker volume named redis-counter-data
. This ensures your counter values survive container restarts.