Skip to content

MonadWizard/redis_django_all_usecase

Repository files navigation

🚀 Redis Django Project

A comprehensive Django project demonstrating various Redis integration patterns including caching, session storage, Celery task queue, pub/sub messaging, rate limiting, analytics, and event sourcing.

🏗️ Architecture Overview

This project showcases 7 different Redis use cases integrated with Django:

  • Authentication (auth_app) - PostgreSQL with JWT tokens
  • Caching (cache_app) - Redis for data caching
  • Sessions (session_app) - Redis session backend
  • Task Queue (celery_app) - Redis as Celery broker
  • Real-time Messaging (pubsub_app) - Redis Pub/Sub
  • Rate Limiting (ratelimit_app) - Redis counters
  • Analytics (analytics_app) - Redis sorted sets & counters
  • Event Sourcing (stream_app) - Redis Streams

🐳 Quick Start with Docker

Prerequisites

  • Docker & Docker Compose installed

1. Start the Project

# Clone and navigate
cd redis_django_project

# Start all services (automated)
./start.sh

2. Manual Setup (Alternative)

# Copy environment file
cp .env.example .env

# Build and start
docker compose up --build -d

# Run migrations
docker compose exec web python manage.py migrate

# Create superuser
docker compose exec web python manage.py createsuperuser

3. Access the Application

📚 API Endpoints

Authentication

  • POST /api/auth/register/ - User registration
  • POST /api/auth/login/ - User login

Caching

  • POST /api/cache/set/ - Set cache value
  • GET /api/cache/get/{key}/ - Get cache value
  • GET /api/cache/stats/ - Cache statistics

Sessions

  • GET /api/session/info/ - Session information
  • POST /api/session/set/ - Set session data

Other Apps

  • /api/celery/ - Celery task management
  • /api/pubsub/ - Real-time messaging
  • /api/analytics/ - Metrics and analytics
  • /api/stream/ - Event sourcing

🔧 Development

View Logs

docker compose logs -f web
docker compose logs -f redis
docker compose logs -f celery

Database Operations

# Django shell
docker compose exec web python manage.py shell

# PostgreSQL
docker compose exec postgres psql -U postgres -d redis_django_db

# Redis CLI
docker compose exec redis redis-cli

Stop Services

docker compose down

📋 Services

Service Port Purpose
Django Web 8000 Main application
PostgreSQL 5432 Primary database
Redis 6379 Cache, sessions, Celery
Celery Worker - Background tasks
Celery Beat - Task scheduler
Nginx 80 Reverse proxy

🧪 Testing

# Run all tests
docker compose exec web python manage.py test

# Specific app
docker compose exec web python manage.py test auth_app

📖 Documentation

For detailed Docker instructions, see: docker_instructions.md

🛠️ Tech Stack

  • Backend: Django 4.2, Django REST Framework
  • Database: PostgreSQL
  • Cache/Broker: Redis
  • Task Queue: Celery
  • Authentication: JWT (SimpleJWT)
  • Containerization: Docker, Docker Compose
  • Proxy: Nginx

🔒 Security Features

  • JWT-based authentication
  • Rate limiting middleware
  • CORS protection
  • Environment-based configuration
  • Non-root Docker containers

Made with ❤️ for learning Redis integration patterns with Django!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published