Installing Redis on WSL Ubuntu and Redis Insights on Windows: A Complete Development Setup

Installing Redis on WSL Ubuntu and Redis Insights on Windows: A Complete Development Setup

Introduction

Setting up a Redis development environment on Windows used to require virtual machines or dual-booting. With Windows Subsystem for Linux (WSL), you can now run Redis natively while maintaining access to powerful Windows-based Redis management tools. This guide walks you through installing Redis on WSL Ubuntu and Redis Insights on Windows, creating a seamless development workflow.

Prerequisites

Before we begin, ensure your system meets these requirements:

  • Windows 10 version 2004 or higher, or Windows 11
  • WSL 2 installed with Ubuntu (20.04 or 22.04 LTS recommended)
  • Administrator access on your Windows machine
  • Basic familiarity with Linux command line and Windows PowerShell

Part 1: Setting Up Redis on WSL Ubuntu

Step 1: System Preparation

Launch your Ubuntu terminal and update the package repository:

sudo apt update
sudo apt upgrade -y

This ensures you have the latest package information and security updates before proceeding.

Step 2: Install Redis Server

Ubuntu’s default repositories include a stable version of Redis. Install it with:

sudo apt install redis-server -y

The installation includes:

  • Redis server (redis-server)
  • Command-line interface (redis-cli)
  • Benchmarking tool (redis-benchmark)
  • Systemd service configuration

Step 3: Configure Redis for WSL Development

Edit the Redis configuration file to optimize it for your WSL environment:

sudo nano /etc/redis/redis.conf

Make the following key changes:

  1. Enable external connections (for Redis Insights access):
    Find the line starting with bind and modify it to:
   bind 127.0.0.1 ::1 0.0.0.0

This allows connections from localhost, IPv6 localhost, and all network interfaces.

  1. Set a secure password (optional but recommended):
    Find the commented # requirepass line and add:
   requirepass your_secure_password_here

Replace with a strong password you’ll remember.

  1. Adjust memory policy (for development):
    Find maxmemory-policy and consider setting it to:
   maxmemory-policy allkeys-lru

This helps prevent memory issues in WSL’s constrained environment.

  1. Enable AOF persistence (optional):
    For better data durability during development:
   appendonly yes
   appendfilename "appendonly.aof"

Save and exit (Ctrl+X, then Y, then Enter in nano).

Step 4: Start and Verify Redis Service

Start the Redis service:

sudo service redis-server start

Check the service status:

sudo service redis-server status

You should see “active (running)” in the output. Test the basic functionality:

redis-cli ping

If configured with a password, authenticate first:

redis-cli
AUTH your_secure_password_here
ping
exit

Step 5: Configure Redis to Start Automatically

Enable Redis to start when WSL launches:

sudo systemctl enable redis-server

If systemctl isn’t available in your WSL installation (some WSL distributions don’t use systemd by default), add this to your ~/.bashrc:

# Start Redis if not running
if ! pgrep -x "redis-server" > /dev/null
then
    sudo service redis-server start > /dev/null 2>&1
fi

Then reload your bash configuration:

source ~/.bashrc

Step 6: Test Advanced Redis Operations

Verify everything is working with a more comprehensive test:

redis-cli
# If password protected:
AUTH your_secure_password_here

# Test data operations
SET welcome "Redis on WSL is working!"
GET welcome

# Test list operations
LPUSH technologies "Redis" "WSL" "Ubuntu"
LRANGE technologies 0 -1

# Check server info
INFO server

exit

Part 2: Installing Redis Insights on Windows

Redis Insights is a powerful GUI tool for visualizing and managing Redis data. Since it’s a Windows application, we’ll install it on the host machine.

Step 1: Download Redis Insights

Visit the official Redis Insights release page:
https://redis.com/redis-enterprise/redis-insights/

Alternatively, you can download it directly from the GitHub releases:
https://github.com/RedisInsights/RedisInsights/releases

Download the Windows installer (typically RedisInsight-v2-win-installer.exe).

Step 2: Install Redis Insights

  1. Run the downloaded installer as administrator
  2. Follow the installation wizard
  3. Choose your preferred installation location
  4. Select whether to create desktop shortcuts
  5. Complete the installation

Step 3: Configure Windows Firewall for WSL Access

Redis running in WSL needs to be accessible from Windows applications. First, find your WSL IP address:

# In WSL Ubuntu terminal
ip addr show eth0 | grep inet

Note the IP address (typically something like 172.x.x.x).

Now, configure Windows Firewall to allow the connection:

  1. Open Windows Defender Firewall with Advanced Security
  2. Click “Inbound Rules” then “New Rule”
  3. Select “Port” and click Next
  4. Select “TCP” and enter “6379” (Redis default port)
  5. Select “Allow the connection” and click Next
  6. Check all profiles (Domain, Private, Public) and click Next
  7. Name the rule “WSL Redis Access” and click Finish

Alternatively, use PowerShell as Administrator:

New-NetFirewallRule -DisplayName "WSL Redis" -Direction Inbound -Protocol TCP -LocalPort 6379 -Action Allow -Enabled True

Step 4: Connect Redis Insights to WSL Redis

  1. Launch Redis Insights from your Start Menu or desktop shortcut
  2. Click “Add Redis Database” or the “+” button
  3. Configure the connection:
  • Host: Enter the WSL IP address you noted earlier
  • Port: 6379 (default Redis port)
  • Name: “WSL Redis” or any descriptive name
  • Username: Leave blank (unless you configured ACL users)
  • Password: Enter the password you set in redis.conf
  1. Click “Test Connection” to verify everything works
  2. Click “Add Redis Database” to save the connection

Step 5: Verify the Connection in Redis Insights

Once connected, explore Redis Insights features:

  1. Dashboard: View key metrics and server information
  2. Browser: Navigate through your Redis keys and data structures
  3. CLI: Access a built-in Redis command-line interface
  4. Slow Log: Monitor slow commands for performance optimization
  5. Memory Analyzer: Identify memory usage patterns

Test the connection by creating a new key through Redis Insights:

  • Go to the Browser tab
  • Click “Add Key”
  • Enter a key name and value
  • Verify it appears in the key list

Part 3: Advanced Configuration and Optimization

WSL Memory Configuration for Redis

Redis performance depends on available memory. Configure WSL memory limits by creating or editing %UserProfile%\.wslconfig on Windows:

[wsl2]
memory=2GB
processors=2
localhostForwarding=true

This allocates 2GB of RAM to WSL. Adjust based on your system’s capabilities and Redis needs.

Setting Up Redis as a Persistent Service

For a more robust setup, create a dedicated startup script:

sudo nano /usr/local/bin/start-redis-dev.sh

Add the following content:

#!/bin/bash

REDIS_CONF="/etc/redis/redis.conf"
LOG_FILE="/var/log/redis/redis-dev.log"

# Check if Redis is already running
if pgrep -x "redis-server" > /dev/null
then
    echo "Redis is already running"
    exit 0
fi

# Start Redis with configuration
echo "Starting Redis for development..."
sudo redis-server $REDIS_CONF --daemonize yes --logfile $LOG_FILE

# Verify startup
sleep 2
if pgrep -x "redis-server" > /dev/null
then
    echo "Redis started successfully"
    echo "Logs available at: $LOG_FILE"
    echo "Connect with: redis-cli -h 127.0.0.1 -p 6379"
else
    echo "Failed to start Redis"
    exit 1
fi

Make it executable and test:

sudo chmod +x /usr/local/bin/start-redis-dev.sh
/usr/local/bin/start-redis-dev.sh

Automating WSL IP Detection for Redis Insights

Since WSL IP addresses can change between sessions, create a PowerShell script to update Redis Insights connection automatically:

# save as Update-RedisConnection.ps1
$wslIp = wsl hostname -I
$wslIp = $wslIp.Trim()

Write-Host "WSL IP Address: $wslIp"
Write-Host "Update your Redis Insights connection to use this IP"
Write-Host "Press any key to continue..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

Part 4: Testing the Complete Setup

Cross-Platform Verification Test

  1. From WSL Ubuntu terminal:
   redis-cli SET test:integration "Data from WSL"
   redis-cli GET test:integration
  1. From Redis Insights on Windows:
  • Open Redis Insights
  • Connect to your WSL Redis instance
  • Go to Browser tab
  • Search for “test:integration”
  • Verify you see “Data from WSL”
  1. From Windows PowerShell:
   # Install Redis CLI for Windows if needed
   # via chocolatey: choco install redis-64
   redis-cli -h <WSL_IP> GET test:integration

Performance Testing

Run a basic benchmark from WSL:

redis-benchmark -h 127.0.0.1 -p 6379 -a your_password -t set,get -n 10000 -q

This tests SET and GET operations to ensure good performance between WSL and Windows.

Troubleshooting Common Issues

Redis Won’t Start in WSL

Check the Redis log:

sudo tail -f /var/log/redis/redis-server.log

Common issues and solutions:

  1. Port already in use: sudo netstat -tlnp | grep :6379
  2. Permission issues: sudo chown redis:redis /var/lib/redis
  3. Configuration error: sudo redis-server /etc/redis/redis.conf --test

Redis Insights Connection Problems

  1. “Connection refused”: Verify Redis is running in WSL and firewall rules are correct
  2. Authentication failed: Double-check the password in /etc/redis/redis.conf
  3. Timeout: Ensure the WSL IP address hasn’t changed

WSL Networking Issues

If Redis Insights can’t connect, try these steps:

  1. Disable Windows Firewall temporarily to test
  2. Use localhost forwarding: Recent WSL versions support connecting via localhost:
   # In redis.conf, ensure bind includes 127.0.0.1
   # In Redis Insights, use 127.0.0.1 as host
  1. Check WSL network mode: Ensure you’re using WSL 2 for better networking

Development Workflow Tips

Using the Combined Setup Effectively

  1. Development Phase: Use Redis Insights to visualize data structures and debug
  2. CLI Operations: Use redis-cli in WSL for quick operations and scripting
  3. Monitoring: Use Redis Insights dashboard to monitor memory usage and performance
  4. Backup and Restore: Use Redis Insights for easy data export/import

Sample Development Session Workflow

# 1. Start your development session
wsl

# 2. Start Redis (if not auto-started)
sudo service redis-server start

# 3. Develop your application
# ... your code that uses Redis ...

# 4. Monitor in Redis Insights
# Open Redis Insights on Windows to debug data

# 5. Run tests
redis-cli FLUSHALL  # Clear test data
# Run your test suite

# 6. Backup before major changes
redis-cli SAVE  # Create RDB backup

Security Considerations for Development

While this setup is for development, follow these security practices:

  1. Use strong passwords even in development
  2. Regularly update both WSL Ubuntu and Redis
  3. Don’t expose your WSL Redis to external networks
  4. Use different passwords for development, staging, and production
  5. Consider Redis ACLs for more granular control in later versions

Maintenance and Updates

Updating Redis in WSL

sudo apt update
sudo apt upgrade redis-server
sudo service redis-server restart

Updating Redis Insights

Check periodically for new releases on the Redis Insights download page and install updates as needed.

Backup Strategy

Implement a simple backup script:

#!/bin/bash
BACKUP_DIR="$HOME/redis-backups"
mkdir -p $BACKUP_DIR
sudo cp /var/lib/redis/dump.rdb $BACKUP_DIR/dump-$(date +%Y%m%d-%H%M%S).rdb
# Keep only last 7 days of backups
find $BACKUP_DIR -name "*.rdb" -mtime +7 -delete

Conclusion

You now have a fully integrated Redis development environment with Redis running in WSL Ubuntu and Redis Insights providing a powerful GUI interface on Windows. This setup combines the performance and familiarity of Linux-based Redis with the convenience of Windows desktop applications.

The key advantages of this approach:

  • Native Redis performance in a Linux environment
  • Powerful GUI management via Redis Insights
  • Seamless integration between Windows and WSL
  • Ideal for development, testing, and learning

Remember that this configuration is optimized for development. For production deployments, always follow Redis security best practices and consider dedicated Redis hosting solutions for critical applications.

Start building with the confidence that you have both the raw power of Redis CLI and the intuitive interface of Redis Insights at your fingertips.

Posts Carousel

Leave a Comment

Your email address will not be published. Required fields are marked with *

Latest Posts

Most Commented

Featured Videos