Updated:

Redis localhost:6379: Connect, Select /0 and Fix Errors

Verify Redis with PING, understand redis://localhost:6379/0, and fix connection refused, NOAUTH, wrong passwords, or Docker host-port mistakes.


redis://localhost:6379/0 connects a Redis client to port 6379, selecting logical database 0. Redis is a database service, so open this URI with redis-cli or your application’s Redis library rather than a web browser.

Read the URL before changing settings

URLMeaning
redis://localhost:6379Local Redis using the default database
redis://localhost:6379/0Explicitly select database 0
redis://:PASSWORD@localhost:6379/0Authenticate as the default user
redis://USER:PASSWORD@localhost:6379/0Authenticate as a named ACL user
redis://127.0.0.1:6380/0Connect through host port 6380
rediss://HOST:PORT/0Use TLS when supported and configured by the server

The number after / is not another port or a filesystem folder. Logical database support depends on deployment mode; Redis Cluster supports database 0 only. See SELECT. Encode reserved characters in credentials when forming a URL.

Start and verify a Docker instance

With Docker running, start a local development instance:

docker run -d --name localhost-redis -p 127.0.0.1:6379:6379 --mount source=localhost-redis-data,target=/data redis:8 redis-server --appendonly yes

The mapping publishes Redis on this computer’s loopback address. If the named container already exists, inspect docker ps -a and use docker start localhost-redis to restart it.

docker exec localhost-redis redis-cli PING

Expected response: PONG. This checks Redis inside the container. With redis-cli installed on the host, verify the published port too:

redis-cli -u redis://127.0.0.1:6379/0 PING

For installation choices on your operating system, use the Redis installation documentation. Docker instructions are documented separately in Run Redis on Docker.

Check a short-lived key in the same database

redis-cli -u redis://127.0.0.1:6379/0 SET localhostrun:check ok EX 60
redis-cli -u redis://127.0.0.1:6379/0 GET localhostrun:check

Expect OK, then "ok". The key expires after 60 seconds. If an application cannot see its own keys, compare its database index, hostname, and port with this client. Avoid assuming an empty database means Redis failed to start.

Fix the error you actually received

ErrorWhat it indicatesNext action
Connection refused / ECONNREFUSEDNo reachable listener at this addressCheck the process and mapping before changing credentials
NOAUTH Authentication requiredServer requires authenticationUse the credentials configured for that instance
WRONGPASSCredentials or user state rejectedCheck ACL username, password, and whether that user is enabled
TimeoutConnection path or server response problemCheck container network, firewall, and server logs
GET returns (nil)Key is absent from the selected databaseCheck DB index, expiration, and instance

For the example container, inspect docker logs --tail 50 localhost-redis and docker port localhost-redis 6379. If port 6379 is occupied, create a separately named instance mapped as 127.0.0.1:6380:6379 and update the host client URL to port 6380.

Inside Compose, an application and a service named redis on the same network use redis://redis:6379/0. The host computer uses the published host port. The two URLs can differ while reaching the same Redis instance. See Docker networking and port conflicts.

Configure your application

For a Node project with ioredis installed:

import Redis from 'ioredis';

const redis = new Redis(process.env.REDIS_URL || 'redis://127.0.0.1:6379/0');
console.log(await redis.ping());
await redis.quit();

Keep the terminal client’s URL and the app’s configuration consistent. The redis-cli reference documents URI connections and authentication. For a URI explanation without a network request, use the localhost URL parser. Related: Redis port 6379 and MongoDB connections.

Local development guides & tools © LocalHost Run