localhost:6379 — Redis

Redis is one of those tools that does ten different things, all of them fast. At its core, it's an in-memory key-value store — think of it as a dictionary that lives in RAM. But people use it for caching database queries, storing user sessions, building real-time leaderboards, message queues, rate limiting APIs, pub/sub messaging, and even as a primary database for some use cases. Port 6379 is where all of this happens.

What makes Redis special isn't the concept (key-value stores aren't new) — it's the speed. Sub-millisecond reads and writes. Everything lives in memory, operations are single-threaded (no locking), and the data structures are implemented in highly optimized C. For most web applications, Redis is the difference between "fast" and "instantaneous."

Talking to Redis

The quickest way to interact with Redis is redis-cli, which ships with every Redis installation:

# Connect (defaults to localhost:6379)
redis-cli

# Test if Redis is alive
redis-cli ping
# Expected: PONG

# Set a key
redis-cli SET greeting "hello world"

# Get it back
redis-cli GET greeting
# "hello world"

# See all keys (careful in production — this can be slow)
redis-cli KEYS *

What Developers Actually Use Redis For

Caching (the #1 use case)

Your database query takes 200ms. The same query, cached in Redis, takes 0.3ms. Multiply that across thousands of requests per second and the performance difference is massive. The pattern is simple: check Redis first, hit the database only on cache miss, store the result in Redis with an expiration time.

# Cache with 1-hour expiration
SET user:1234 "{\"name\":\"Vivaan\",\"email\":\"...\"}" EX 3600

# Check if cached
GET user:1234

Session Storage

Storing user sessions in Redis instead of files or database tables means your sessions survive server restarts, work across multiple app servers (load balancing), and are lightning fast to read/write. Express.js with connect-redis, Laravel with the Redis session driver, Django with django-redis — they all plug in trivially.

Rate Limiting

Need to limit API requests to 100 per minute per user? Redis's atomic increment and expiration make this trivial:

# Increment counter for this user's requests
INCR rate:user:1234
# Set expiry on first request (60 seconds)
EXPIRE rate:user:1234 60
# Check count
GET rate:user:1234

Queues (with BullMQ, Sidekiq, Celery)

Redis lists work as lightweight job queues. Push jobs onto a list, worker processes pop them off. Libraries like BullMQ (Node.js), Sidekiq (Ruby), and Celery (Python) all use Redis as their queue backend. It's reliable enough for most background job needs without the complexity of a dedicated message broker like RabbitMQ.

Pub/Sub

Redis can broadcast messages between processes in real time. One process publishes to a channel, all subscribed processes receive it instantly. Used for chat systems, live notifications, and coordinating between microservices.

Installing and Starting Redis

# macOS
brew install redis
brew services start redis

# Ubuntu/Debian
sudo apt install redis-server
sudo systemctl start redis-server
sudo systemctl enable redis-server

# Docker (fastest way)
docker run -d --name redis -p 6379:6379 redis:7-alpine

# Verify it's running
redis-cli ping    # Should return: PONG

Connecting From Your Application

# Node.js (ioredis — the better Redis client)
const Redis = require('ioredis');
const redis = new Redis();  // defaults to localhost:6379
await redis.set('key', 'value');
const val = await redis.get('key');

# Python (redis-py)
import redis
r = redis.Redis(host='localhost', port=6379, db=0)
r.set('key', 'value')
r.get('key')

# PHP (predis)
$client = new Predis\Client();
$client->set('key', 'value');
$client->get('key');

# Laravel (.env)
REDIS_HOST=127.0.0.1
REDIS_PORT=6379

# Spring Boot (application.properties)
spring.redis.host=localhost
spring.redis.port=6379

Data Doesn't Persist After Restart?

By default, Redis does persist data — but the behavior depends on your configuration. Redis has two persistence mechanisms:

RDB snapshots — Redis periodically saves the entire dataset to disk (a file called dump.rdb). Default schedule: save after 3600 seconds if at least 1 key changed, or 300 seconds if 100 keys changed, or 60 seconds if 10,000 keys changed. Good for backups, but you can lose the last few minutes of data on a crash.

AOF (Append Only File) — logs every write operation to disk. Much more durable — you lose at most 1 second of data. Enable it with appendonly yes in redis.conf.

If you're using Docker without a volume mount, data dies with the container. Always mount a volume for persistence:

docker run -d --name redis -p 6379:6379 \
  -v redis_data:/data redis:7-alpine

When Redis Won't Connect

"Connection refused" on 6379: Redis isn't running. Start it with the appropriate command above and verify with redis-cli ping.

Redis is running but your app can't connect: Check the bind directive in redis.conf. By default, Redis only accepts connections from 127.0.0.1. If your app is in a Docker container on a bridge network, it can't reach the host's 127.0.0.1. Either change the bind to 0.0.0.0 (with a password!) or use Docker networking.

"NOAUTH Authentication required": Redis has the requirepass directive set. Either provide the password in your connection (redis-cli -a yourpassword) or check redis.conf for the configured password.

Max memory reached: Redis will start evicting keys based on the eviction policy when it hits the maxmemory limit. Check with redis-cli INFO memory. If used_memory equals maxmemory, either increase the limit in redis.conf or review what's consuming space with redis-cli --bigkeys.