Redis for Python - via Docker - No direct WSL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MyrinNew
    Senior Member
    • Feb 2024
    • 5175

    #1

    Redis for Python - via Docker - No direct WSL

    Redis doesn’t officially support native Windows installations anymore. Instead of setting up WSL (Windows Subsystem for Linux), Docker is the easier and more modern way to run Redis on a Windows machine.


    Installing Docker Desktop gives you a full environment where you can run Redis (and many other tools) without friction.


    πŸ”Ή Step 1: Install Docker Desktop

    Download and install Docker Desktop from:

    Docker Desktop is collaborative containerization software for developers. Get started and download Docker Desktop today on Mac, Windows, or Linux.



    Once installed:

    Make sure Docker is running (look for the whale icon in your system tray).

    Enable WSL2 integration if prompted during installation.


    πŸ”Ή Step 2: Pull and Run Redis

    Open PowerShell or Command Prompt and run:


    docker run --name my-redis -p 6379:6379 -d redis

    docker ps


    πŸ”Ή Step 3: Connect to Redis

    docker exec -it my-redis redis-cli

    set name "DockerRedis"

    get name

    ping


    Install RedisInsight and connect to:

    Debug and visualize Redis fast with Redis Insight. Cross-platform, AI-powered, and free. Supports all Redis setups. Download now.


    Host: localhost

    Port: 6379





    To find out whether your Windows PC uses an ARM64 or AMD64 (also called x64) architecture, follow these

    from Command Prompt you can run:


    C:\Users\pepsara>echo %PROCESSOR_ARCHITECTURE%


    AMD64

    C:\Users\pepsara>docker version

    Client:

    Version: 28.0.4

    API version: 1.48

    Go version: go1.23.7

    Git commit: b8034c0

    Built: Tue Mar 25 15:07:48 2025

    OS/Arch: windows/amd64

    Context: desktop-linux


    Server: Docker Desktop 4.40.0 (187762)

    Engine:

    Version: 28.0.4

    API version: 1.48 (minimum version 1.24)

    Go version: go1.23.7

    Git commit: 6430e49

    Built: Tue Mar 25 15:07:22 2025

    OS/Arch: linux/amd64

    Experimental: false

    containerd:

    Version: 1.7.26

    GitCommit: 753481ec61c7c8955a23d6ff7bc8e4daed455734

    runc:

    Version: 1.2.5

    GitCommit: v1.2.5-0-g59923ef

    docker-init:

    Version: 0.19.0

    GitCommit: de40ad0


    C:\Users\pepsara>docker info

    βœ… Step-by-Step: Use Redis with Python in VS Code

    πŸ”§ 1. Install Redis client for Python

    In your terminal (inside VS Code), run:

    pip install redis


    πŸ§ͺ 2. Test Redis Connection in Python

    Create a new Python file, e.g., redis_test.py, and add the following code:

    import redis


    Connect to Redis

    r = redis.Redis(host='localhost', port=6379, db=0)


    Set a key

    r.set('mykey', 'Hello Redis!')


    Get the key

    value = r.get('mykey')

    print(value.decode('utf-8')) # Output: Hello Redis!


    Then run it: python redis_test.py

    You should see: Hello Redis!




    More...
Working...