redis-cli says Connection refused on a Mac with Homebrew
Could not connect to Redis at 127.0.0.1:6379: Connection refusedShort answer
Connection refused means nothing is listening on that port. After brew install redis the server is not started for you. Start it as a background service with brew services, or run redis-server in a terminal, then test with redis-cli ping. If it still refuses, check the port and the bind line.
Fix it fast
1Find out which cause you have
Ask Homebrew whether the Redis service is running.
brew services info redis2Match what you see, then jump to its fix
- 1
brew services info redis shows Running with a cross, or no service line.The server was installed but never startedFix - 2
brew services start prints Successfully started, but redis-cli still refuses a few seconds later.The service starts and stops againFix - 3
pgrep shows redis-server, but redis-cli to the default address refuses.Redis runs on another port or is bound to a different addressFix
- 1
What does the error look like?
Could not connect to Redis at 127.0.0.1:6379: Connection refused
Cause 1 of 3
The server was installed but never started
1Check
The Homebrew package installs the binaries only. Start it yourself, in the foreground to see logs, or as a launchd service.
brew list redis
pgrep -l redis-server2Fix
Start it as a background service that also restarts at login. For a quick test, run redis-server in a terminal instead and stop it with Ctrl-C.
brew services start redis
# or, in the foreground
redis-server3Verify
The server answers.
redis-cli pingConfirmed by redis.io
Cause 2 of 3
The service starts and stops again
1Check
Run the server in the foreground. A bad config line or a port in use is printed on the console and then Redis exits.
brew services stop redis
redis-server2Fix
Fix the line the console names. If the port is taken, find the other process or give Redis another port in its config.
lsof -nP -iTCP:6379 -sTCP:LISTEN3Verify
Start the service again and ping.
brew services start redis
redis-cli pingConfirmed by redis.io
Cause 3 of 3
Redis runs on another port or is bound to a different address
1Check
A server started with --port or a bind line in redis.conf will not answer on 127.0.0.1:6379. Ask the process what it listens on.
lsof -nP -iTCP -sTCP:LISTEN | grep redis2Fix
Point the client at the real address, or change the config and restart.
redis-cli -h 127.0.0.1 -p 6380 ping3Verify
The reply is PONG.
redis-cli -p 6380 pingConfirmed by redis.io
How do I stop it coming back?
- Use brew services for a dev server you keep, so it comes back after a reboot.
- Put the host and port in one environment variable that both the app and redis-cli read.
- Run one Redis per port; stop the old one before you start another.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Node.js cannot reach Redis: ECONNREFUSED on port 6379
Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
ECONNREFUSED on 6379 means no Redis server accepted the connection at the address the client used.
4 causes, each with a fixDatabases
Jedis cannot borrow a connection from its pool
Caused by: java.net.SocketTimeoutException
The pool could not give the code a working connection in time.
3 causes, each with a fixDatabases
node-redis throws ConnectionTimeoutError on connect
Redis Client Error ConnectionTimeoutError
node-redis raises ConnectionTimeoutError when the socket does not connect within socket.connectTimeout, which is 5000 ms by default.
3 causes, each with a fixDatabases
node-redis throws The client is closed when you send a command
ClientClosedError: The client is closed
node-redis throws ClientClosedError when the client's socket is not open.
3 causes, each with a fixDatabases
Redis cannot save dump.rdb because it is not allowed to write there
Permission denied
Redis writes its snapshot into the directory set by dir, using the account the server runs as.
3 causes, each with a fixDatabases
Redis answers every command with LOADING after a restart
(error) LOADING Redis is loading the dataset in memory
LOADING means the server is up but still reading its RDB or AOF file back into memory, so it refuses most commands until that finishes.
3 causes, each with a fix