Skip to content
Star
478
Star
478

Redis Mutex

This guide shows you how to implement a distributed mutex using Redis, Docker Compose, and Python. This lab demonstrates how to coordinate concurrent access to shared resources across multiple threads.

  1. Setup Environment:

    Open VS Code in the project folder and execute this command in the Command Palette:

    Terminal window
    > Dev Containers: Reopen in Container
  2. Start Infrastructure: Launch the Redis container:

    Terminal window
    docker compose up -d
  3. Run the Example:

    Terminal window
    python main.py

Verify that each thread wrote its line in order by checking shared_file.txt:

Terminal window
cat shared_file.txt
Terminal window
docker compose down -v
rm shared_file.txt