localhost:6379

localhost:6379

Port 6379 is the default port for Redis, an open-source in-memory data structure store. Redis is used as a database, cache, message broker, and streaming engine, known for sub-millisecond response times and support for diverse data structures.

What is Redis?

Redis (Remote Dictionary Server) is an in-memory key-value store that provides:

  • Lightning-Fast Performance - Sub-millisecond latency
  • Rich Data Structures - Strings, hashes, lists, sets, sorted sets, bitmaps
  • Persistence Options - RDB snapshots and AOF logging
  • Replication - Master-slave replication
  • High Availability - Redis Sentinel for failover
  • Clustering - Automatic sharding across nodes
  • Pub/Sub Messaging - Publish/subscribe pattern
  • Lua Scripting - Server-side scripting
  • Transactions - Atomic command execution
  • TTL Support - Automatic key expiration

Redis Use Cases

  • Caching - Database query results, API responses, session data
  • Session Store - Web application session management
  • Real-time Analytics - Leaderboards, counters, metrics
  • Message Queue - Task queues, job processing
  • Pub/Sub - Chat applications, live notifications
  • Rate Limiting - API throttling, DDoS protection
  • Geospatial - Location-based services
  • Full-text Search - With RediSearch module

Install Redis

Linux (Ubuntu/Debian)

# Update package list sudo apt update # Install Redis sudo apt install redis-server # Start Redis service sudo systemctl start redis-server # Enable on boot sudo systemctl enable redis-server # Check status sudo systemctl status redis-server # Access Redis CLI redis-cli

Mac (Homebrew)

# Install Redis brew install redis # Start Redis service brew services start redis # Or start manually redis-server # Check if running brew services list | grep redis # Access Redis CLI redis-cli

Windows

# Download Redis for Windows from: # https://github.com/microsoftarchive/redis/releases # Or use WSL2 with Linux instructions # Or use Docker docker run --name redis -d -p 6379:6379 redis # Access Redis CLI redis-cli # Or through Docker docker exec -it redis redis-cli

Docker

# Run Redis container docker run -d --name redis -p 6379:6379 redis # Run with persistence docker run -d --name redis -p 6379:6379 \ -v redis-data:/data redis redis-server --appendonly yes # Access Redis CLI docker exec -it redis redis-cli # Stop Redis docker stop redis # Remove container docker rm redis

Connect to Redis on Port 6379

Redis CLI

# Connect to Redis on localhost redis-cli -h localhost -p 6379 # Shorthand (defaults to localhost:6379) redis-cli # Test connection 127.0.0.1:6379> PING PONG # Connect with authentication redis-cli -h localhost -p 6379 -a your_password # Or authenticate after connecting 127.0.0.1:6379> AUTH your_password OK # Connect to specific database (0-15) redis-cli -n 1 # Exit Redis CLI 127.0.0.1:6379> EXIT # Or press Ctrl+D

Check if Redis is Running

# Test connection redis-cli ping # Should return: PONG # Check Redis process # Linux ps aux | grep redis # Mac ps aux | grep redis # Windows tasklist | findstr redis # Check if listening on port 6379 # Windows netstat -ano | findstr :6379 # Linux/Mac sudo lsof -i :6379 netstat -an | grep 6379

Basic Redis Commands

# String operations SET key "value" GET key APPEND key " more" STRLEN key INCR counter DECR counter INCRBY counter 5 # Key management EXISTS key DEL key KEYS * KEYS user:* TTL key EXPIRE key 3600 PERSIST key # Hash operations HSET user:1 name "John" age 30 HGET user:1 name HGETALL user:1 HDEL user:1 age # List operations LPUSH mylist "item1" RPUSH mylist "item2" LRANGE mylist 0 -1 LPOP mylist LLEN mylist # Set operations SADD myset "member1" SMEMBERS myset SISMEMBER myset "member1" SCARD myset # Sorted Set operations ZADD leaderboard 100 "player1" ZRANGE leaderboard 0 -1 WITHSCORES ZRANK leaderboard "player1" # Database operations SELECT 1 FLUSHDB FLUSHALL DBSIZE INFO

Connect from Programming Languages

Node.js

// npm install redis const redis = require('redis'); const client = redis.createClient({ host: 'localhost', port: 6379, password: 'your_password' // if auth enabled }); client.on('connect', () => { console.log('Connected to Redis'); }); client.on('error', (err) => { console.error('Redis error:', err); }); // Set value client.set('key', 'value', (err, reply) => { console.log(reply); // OK }); // Get value client.get('key', (err, reply) => { console.log(reply); // value }); // With promises (redis v4+) const redis = require('redis'); const client = redis.createClient(); await client.connect(); await client.set('key', 'value'); const value = await client.get('key'); console.log(value); await client.disconnect();

Python

# pip install redis import redis # Connect to Redis r = redis.Redis( host='localhost', port=6379, db=0, password='your_password', # if auth enabled decode_responses=True # return strings instead of bytes ) # Test connection r.ping() # Returns True # Set value r.set('key', 'value') # Get value value = r.get('key') print(value) # value # Set with expiration r.setex('temp_key', 60, 'expires in 60 seconds') # Hash operations r.hset('user:1', mapping={'name': 'John', 'age': 30}) user = r.hgetall('user:1') print(user) # {'name': 'John', 'age': '30'} # List operations r.lpush('mylist', 'item1', 'item2') items = r.lrange('mylist', 0, -1) print(items) # Connection pool pool = redis.ConnectionPool(host='localhost', port=6379, db=0) r = redis.Redis(connection_pool=pool)

PHP

<?php // Install: pecl install redis // Or use Predis: composer require predis/predis // Using phpredis extension $redis = new Redis(); $redis->connect('localhost', 6379); // Authenticate if needed $redis->auth('your_password'); // Set value $redis->set('key', 'value'); // Get value $value = $redis->get('key'); echo $value; // value // Set with expiration $redis->setex('temp_key', 60, 'expires in 60 seconds'); // Hash operations $redis->hMSet('user:1', ['name' => 'John', 'age' => 30]); $user = $redis->hGetAll('user:1'); print_r($user); // List operations $redis->lPush('mylist', 'item1'); $items = $redis->lRange('mylist', 0, -1); print_r($items); // Close connection $redis->close(); // Using Predis require 'vendor/autoload.php'; $client = new Predis\Client([ 'scheme' => 'tcp', 'host' => 'localhost', 'port' => 6379, ]); $client->set('key', 'value'); $value = $client->get('key'); ?>

Java

// Add Jedis dependency to pom.xml // <dependency> // <groupId>redis.clients</groupId> // <artifactId>jedis</artifactId> // <version>4.3.0</version> // </dependency> import redis.clients.jedis.Jedis; public class RedisExample { public static void main(String[] args) { // Connect to Redis Jedis jedis = new Jedis("localhost", 6379); // Test connection String response = jedis.ping(); System.out.println(response); // PONG // Set value jedis.set("key", "value"); // Get value String value = jedis.get("key"); System.out.println(value); // Set with expiration jedis.setex("temp_key", 60, "expires in 60 seconds"); // Hash operations jedis.hset("user:1", "name", "John"); jedis.hset("user:1", "age", "30"); Map<String, String> user = jedis.hgetAll("user:1"); System.out.println(user); // Close connection jedis.close(); } }

Fix "Connection refused" on Port 6379

Error: Could not connect to Redis at localhost:6379

Redis server is not running.

  • Start Redis service
  • Check if Redis process is running
  • Verify Redis is listening on port 6379
  • Check Redis configuration file
  • Review Redis logs for errors
# Start Redis service # Linux sudo systemctl start redis-server sudo service redis-server start # Mac brew services start redis redis-server # Windows (WSL2 or use Docker) docker start redis # Check if Redis is running redis-cli ping # Check Redis process ps aux | grep redis # View Redis logs # Linux sudo tail -f /var/log/redis/redis-server.log # Mac tail -f /usr/local/var/log/redis.log

Error: NOAUTH Authentication required

Redis requires password authentication.

# Connect with password redis-cli -a your_password # Or authenticate after connecting redis-cli 127.0.0.1:6379> AUTH your_password OK # Set password in redis.conf requirepass your_strong_password # Restart Redis sudo systemctl restart redis-server

Error: Port 6379 already in use

Another Redis instance or application is using port 6379.

# Find what's using port 6379 # Windows netstat -ano | findstr :6379 # Linux/Mac sudo lsof -i :6379 sudo netstat -tulpn | grep :6379 # Kill Redis process sudo kill -9 [PID] # Or stop Redis service sudo systemctl stop redis-server

Redis Configuration

redis.conf Location

System Configuration File
Linux /etc/redis/redis.conf
Mac (Homebrew) /usr/local/etc/redis.conf
Docker Mount custom config file

Important Configuration Options

# redis.conf # Bind to specific IP (default: 127.0.0.1) bind 127.0.0.1 # Or allow all connections bind 0.0.0.0 # Port number port 6379 # Password authentication requirepass your_strong_password # Max memory maxmemory 256mb maxmemory-policy allkeys-lru # Persistence - RDB snapshots save 900 1 # Save after 900 sec if 1 key changed save 300 10 # Save after 300 sec if 10 keys changed save 60 10000 # Save after 60 sec if 10000 keys changed # AOF persistence appendonly yes appendfilename "appendonly.aof" # Restart Redis after config changes sudo systemctl restart redis-server

Change Redis Port from 6379

# Edit redis.conf sudo nano /etc/redis/redis.conf # Change port port 6380 # Save and restart Redis sudo systemctl restart redis-server # Connect to new port redis-cli -p 6380 # Update application connections to use port 6380

Redis Security Best Practices

  • Set strong password: requirepass strong_random_password
  • Bind to localhost only: bind 127.0.0.1 (unless remote access needed)
  • Rename dangerous commands: rename-command FLUSHALL ""
  • Enable protected mode: protected-mode yes
  • Use firewall: Block port 6379 from internet
  • Regular backups: Schedule RDB snapshots
  • Monitor logs: Check for suspicious activity
  • Use TLS: Enable SSL/TLS encryption
  • Limit connections: maxclients 10000
  • Keep updated: Use latest stable Redis version
Security Warning: By default, Redis has no authentication and binds to all interfaces. ALWAYS set a strong password with requirepass and bind to localhost only unless remote access is explicitly needed. Never expose Redis to the internet without proper security.

Redis Persistence Options

Method Description Pros Cons
RDB (Snapshots) Point-in-time snapshots Compact, fast recovery Data loss between snapshots
AOF (Append Only File) Log all write operations Better durability Larger files, slower recovery
RDB + AOF Both methods combined Best of both More disk space
No Persistence Cache only, no saving Fastest performance All data lost on restart

Redis Monitoring

# Real-time monitoring redis-cli --stat # Get server info redis-cli INFO # Monitor all commands redis-cli MONITOR # Get specific stats redis-cli INFO stats redis-cli INFO memory redis-cli INFO replication # Check connected clients redis-cli CLIENT LIST # Get slow log redis-cli SLOWLOG GET 10 # Memory usage redis-cli MEMORY USAGE key_name
Performance Tip: Redis can handle millions of operations per second. For caching use cases, set appropriate TTL values to automatically expire keys and prevent memory overflow.

Frequently Asked Questions

Can I access Redis port 6379 in browser?

No. Port 6379 uses Redis protocol, not HTTP. Use Redis CLI or GUI tools like RedisInsight, Redis Commander, or Medis to interact with Redis.

Why does Redis use port 6379?

Creator Salvatore Sanfilippo chose 6379 because it corresponds to "MERZ" on a phone keypad, named after Italian TV host Alessia Merz.

Is Redis database or cache?

Both. Redis is primarily an in-memory cache but supports persistence (RDB/AOF), making it suitable as both a cache and database.

How much data can Redis store?

Limited by available RAM. Configure maxmemory in redis.conf. When limit reached, Redis evicts keys based on maxmemory-policy.

Can multiple applications use Redis on port 6379?

Yes. Redis supports multiple connections simultaneously. Use different databases (0-15) or key prefixes to separate application data.

Related Ports and Resources