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

ItemValue
Hostlocalhost
Port6379
PasswordTypically 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 PONG

Ubuntu:

sudo apt install redis-server
sudo systemctl start redis-server

Docker:

docker run -d --name redis -p 6379:6379 redis:7

Command 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

ScenarioDescription
API CachingReduces database load
SessionExpress/connect-redis, Next.js adapter
Task QueuesBull, BullMQ (commonly used in NestJS)
Rate Limiting / CountingSliding 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.

访客计数:------ Best viewed in Netscape Navigator · 800×600 © LocalHost Run