vibecode.wiki
RU EN
~/wiki / dannye-i-khranenie / redis-dlya-yskoreniya-proectov

Redis to speed up projects: cache, queues and rate limiting

◷ 4 min read 2/19/2026

Main chat

A chat for vibe coders: news, guides, live cases, marketplace, and finding executors.

$ cd section/ $ join vibe dev

If you have already started your project in Docker and forgot about “works for me”. Now add Redis — it’s like the super-fast brain of your app, which keeps everything in RAM and is responsible for milliseconds.

Without Redis, your bot/site will slow down on every database request. With Redis, flying.

What is Redis in Simple Words

Redis (REmote DIctionary Server) is an in-memory key-value storage that lives entirely in RAM.

Imagine a huge Python dictionary, { "user:123": {...} }, which is stored in the computer’s memory, not on disk. Just this dictionary:

  • it works in any language (Node, Python, Go, Rust...)
  • performs millions of operations per second
  • it supports not just strings, but a bunch of cool data structures

Major data types in Redis:

  • String (simple values, JSON, counters)
  • Hash (as object: user:123 → {name, email, balance})
  • List (task queues)
  • Set / Sorted Set (unique elements, leaderboards)
  • Stream (logs, chats, events)
  • Bitmap, HyperLogLog, Geospatial, and even JSON

How Redis works

  1. You throw the data, it's in RAM.
  2. Read it instantly (10-100 times faster than any disk database).
  3. At the request of Redis itself saves data to the disk:
    • *RDB – a snapshot of every N minutes/operations
    • AOF - log of each operation (maximum reliability)

If the server crashes, Redis will download the data back in seconds.

** Comparison:**

  • PostgreSQL/MySQL - a reliable warehouse
  • Redis - lightning cache + queues + counters

Why is Redis needed

  • Caching API responses (saving 80% of the database load)
  • User sessions (without a bunch of tables)
  • Rate limiting (no more than 10 requests per minute per user)
  • Task queues (BullMQ, RQ, Celery)
  • Pub/Sub and WebSocket rooms
  • Semantic cache for AI-agents (storage embedding requests)
  • Leaderboards, likes counters, online status

The easiest way to start is Docker

No setup on the host. Just docker-compose.

Universal Prompt for Claude/Cursor/Codex:

code
Create production-ready docker-compose.yml for the stack:

Postgres (or your primary database)
Redis 8 (use redis:8-alpine)

Requirements:
- Redis with persistence (RDB + AOF)
- Password for Redis (from .env)
Volumes for data (so as not to be lost during restart)
Networks + depend on
- healthcheck for Redis
- .env.example with REDIS HOST, REDIS PORT, REDIS PASSWORD
Comments on each service

Also write ready-made redis.conf (if needed) and an example connection in the application code.

An example of a ready-made docker-compose (after the prompt)

yaml
services:
  redis:
    image: redis:8-alpine
    container_name: myapp-redis
    command: redis-server /usr/local/etc/redis/redis.conf
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
      - ./redis.conf:/usr/local/etc/redis/redis.conf
    environment:
      - REDIS_PASSWORD=${REDIS_PASSWORD}
    healthcheck:
      test: ["CMD", "redis-cli", "-a", "${REDIS_PASSWORD}", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5
    restart: unless-stopped

volumes:
  redis_data:

Prompts for integration into code

** For Python (FastAPI/aiogram):**

code
Write the Redis connection code in FastAPI using redis-py (async).
Add:
Caching GET requests for 5 minutes
- rate limiter
- an example of storing a user session
- Handling Redis disconnection

** For Next.js:**

code
Connect to Redis in Next.js 15 (app router) via ioredis.
Do a get/set helper with TTL and an example of semantic cache for AI responses.

Useful teams after launch

bash
docker compose exec redis redis-cli -a ТВОЙ_ПАРОЛЬ
> PING → PONG
> SET test "Hello Redis" EX 60   # живёт 60 сек
> KEYS *

Advice

  • Always put your password + don't open 6379 on the Internet
  • Use redis:8-alpine – image size ~10 MB
  • For production - Redis Sentinel or Cluster (Claude will write)
  • Memory Monitor: INFO memory
  • Do not store data in Redis that cannot be lost (cache + queue only)