Redis Local Usage Guide
Run Redis on localhost:6379 for local caching, sessions, queues, and development debugging with NestJS/Bull.
Redis is an in-memory key-value database commonly used for caching, session storage, message queues, and real-time counting. The default local connection is localhost:6379.
Default Connection
| Item | Value |
|---|---|
| Host | localhost |
| Port | 6379 |
| Password | Typically none locally (must be set in production) |
Connection URL: redis://localhost:6379
Installation and Startup
macOS:
brew install redis
brew services start redis
redis-cli ping # Should return PONGUbuntu:
sudo apt install redis-server
sudo systemctl start redis-serverDocker:
docker run -d --name redis -p 6379:6379 redis:7Command Line Examples
redis-cli
SET user:1 "Alice"
GET user:1
KEYS *
FLUSHALL # Clears all keys (use with caution in development)Typical Local Use Cases
| Scenario | Description |
|---|---|
| API Caching | Reduces database load |
| Session | Express/connect-redis, Next.js adapter |
| Task Queues | Bull, BullMQ (commonly used in NestJS) |
| Rate Limiting / Counting | Sliding window, access statistics |
Using with Docker Compose
services:
redis:
image: redis:7
ports:
- '6379:6379'Set environment variable: REDIS_URL=redis://localhost:6379
Frequently Asked Questions
Port 6379 is occupied
There may already be Redis or another service running; check with lsof -i :6379, or change Docker mapping to 6380:6379.
Unable to connect remotely
Keep bind 127.0.0.1 for local development; do not expose a passwordless Redis to the public.
Difference from Memcached
Redis supports more data structures (Hash, List, Set, Sorted Set), making it more commonly used in modern projects.
Summary
Redis defaults to localhost:6379 locally, is lightweight, and is a standard component for caching and queues in stacks like Node/Python/Laravel.