Part of Hosting by frameworkHosting · Troubleshooting

“Error: connect ECONNREFUSED 127.0.0.1:6379”: your Redis client never got the URL.

connect ECONNREFUSED 127.0.0.1:6379 means the Redis client dialled its default address, the machine it runs on, and nothing listened there. In production that almost always means the client never received the connection URL: the variable is missing or misnamed, it was read at build time, or the code ignores it. Pass the URL explicitly and fail when it’s missing.

Facts checked

What the error looks like

ioredis, node-redis, redis-py and BullMQ all default to localhost on port 6379 when you don’t give them an address. Your laptop runs Redis there; a server or container usually doesn’t. These are the messages from our own runs with no Redis listening:

# ioredis 6.1 on Node 22, no URL given: it tries localhost, which is ::1 and 127.0.0.1
[ioredis] Unhandled error event: AggregateError [ECONNREFUSED]:
#   err.errors -> connect ECONNREFUSED ::1:6379 / connect ECONNREFUSED 127.0.0.1:6379

# ioredis or node-redis given redis://127.0.0.1:6379, or an older Node resolving localhost to IPv4
connect ECONNREFUSED 127.0.0.1:6379

# redis-py 8.2, no URL given (the number and text after "Error" come from the OS; this run was on Windows)
redis.exceptions.ConnectionError: Error 10061 connecting to localhost:6379. No connection could be made because the target machine actively refused it.

The causes, and the fix for each

CauseHow to tellFix
The variable isn’t set where the app runs, so new Redis(process.env.REDIS_URL) gets undefined and uses the defaults. An empty string does the same in ioredis † †The check below prints NOT SET and localhostSet it in this service and environment. Make the code throw when it’s missing instead of falling back
The platform names it differently from what the code reads. Railway’s Redis service exposes REDIS_URL, REDISHOST, REDISPORT (no underscore), REDISUSER and REDISPASSWORD, and another service only sees them through a reference such as ${{Redis.REDIS_URL}}. Heroku sets REDIS_URL for the first add-on; a second one attaches as HEROKU_REDIS_<COLOR> † † †Code reads REDIS_HOST, the dashboard shows REDISHOST; or the variable lives on the Redis service, not on yoursRead the one URL variable the platform gives you, and add the reference on your app’s service
The client connects at build time or when a module is imported. Railway’s private network is available “only at runtime, not during the build phase”, and Fly secrets are “only available at run-time” † †The error is in the build log, often during next build while it collects page dataCreate the client lazily (below), or give it lazyConnect: true and connect on first use
Docker or Compose: inside a container, localhost is the container itself †Works with Redis on the host, fails in docker compose upUse the service name: redis://redis:6379 when the Compose service is called redis
A private hostname the client can’t reach in its address family. Railway environments created before 16 October 2025 resolve private names to IPv6 only; ioredis before 5.8.2 asked DNS for IPv4 only by default † † †ENOTFOUND or ECONNREFUSED on a .railway.internal nameUpgrade ioredis or add family: 0 (?family=0 on the URL), as Railway’s docs show
TLS: the provider wants rediss:// and the URL or client dropped it, or the certificate is self-signed. Every Heroku Key-Value Store plan requires TLS, with a self-signed certificate † †Usually ECONNRESET or a closed connection rather than refused; tls: false in the checkKeep the rediss:// scheme. For Heroku, its docs pass tls: { rejectUnauthorized: false } (ioredis), socket: { rejectUnauthorized: false } (node-redis) or ssl_cert_reqs=None (redis-py)

† Competitor details come from each vendor’s own published pages on the dates shown; prices and plans change, so check the vendor before you decide. The variable isn’t set where the app runs, so `new Redis(process.env.REDIS_URL)` gets `undefined` and uses the defaults. An empty string does the same in ioredis (2026-11-25) · The variable isn’t set where the app runs, so `new Redis(process.env.REDIS_URL)` gets `undefined` and uses the defaults. An empty string does the same in ioredis (2026-11-25) · The platform names it differently from what the code reads. Railway’s Redis service exposes `REDIS_URL`, `REDISHOST`, `REDISPORT` (no underscore), `REDISUSER` and `REDISPASSWORD`, and another service only sees them through a reference such as `${{Redis.REDIS_URL}}`. Heroku sets `REDIS_URL` for the first add-on; a second one attaches as `HEROKU_REDIS_<COLOR>` (2026-11-25) · The platform names it differently from what the code reads. Railway’s Redis service exposes `REDIS_URL`, `REDISHOST`, `REDISPORT` (no underscore), `REDISUSER` and `REDISPASSWORD`, and another service only sees them through a reference such as `${{Redis.REDIS_URL}}`. Heroku sets `REDIS_URL` for the first add-on; a second one attaches as `HEROKU_REDIS_<COLOR>` (2026-11-25) · The platform names it differently from what the code reads. Railway’s Redis service exposes `REDIS_URL`, `REDISHOST`, `REDISPORT` (no underscore), `REDISUSER` and `REDISPASSWORD`, and another service only sees them through a reference such as `${{Redis.REDIS_URL}}`. Heroku sets `REDIS_URL` for the first add-on; a second one attaches as `HEROKU_REDIS_<COLOR>` (2026-11-25) · The client connects at build time or when a module is imported. Railway’s private network is available “only at runtime, not during the build phase”, and Fly secrets are “only available at run-time” (2026-11-25) · The client connects at build time or when a module is imported. Railway’s private network is available “only at runtime, not during the build phase”, and Fly secrets are “only available at run-time” (2026-11-25) · Docker or Compose: inside a container, `localhost` is the container itself (2026-11-25) · A private hostname the client can’t reach in its address family. Railway environments created before 16 October 2025 resolve private names to IPv6 only; ioredis before 5.8.2 asked DNS for IPv4 only by default (2026-11-25) · A private hostname the client can’t reach in its address family. Railway environments created before 16 October 2025 resolve private names to IPv6 only; ioredis before 5.8.2 asked DNS for IPv4 only by default (2026-11-25) · A private hostname the client can’t reach in its address family. Railway environments created before 16 October 2025 resolve private names to IPv6 only; ioredis before 5.8.2 asked DNS for IPv4 only by default (2026-11-25) · TLS: the provider wants `rediss://` and the URL or client dropped it, or the certificate is self-signed. Every Heroku Key-Value Store plan requires TLS, with a self-signed certificate (2026-11-25) · TLS: the provider wants `rediss://` and the URL or client dropped it, or the certificate is self-signed. Every Heroku Key-Value Store plan requires TLS, with a self-signed certificate (2026-11-25)

Check what the client actually got

Run this with the same environment as the app (railway run, heroku run, fly ssh console, or in the container). With lazyConnect, ioredis builds its options without dialling, so you see the host, port, family and TLS setting it will use before it fails.

// check-redis.mjs: run it with the app's environment, e.g. `railway run node check-redis.mjs`
import Redis from "ioredis";

console.log("REDIS_URL is", process.env.REDIS_URL ? "set" : "NOT SET");
const redis = new Redis(process.env.REDIS_URL, { lazyConnect: true });
const { host, port, family, tls, path } = redis.options;
console.log({ host, port, family, tls: Boolean(tls), path });
await redis.connect();
console.log(await redis.ping());
redis.disconnect();

// NOT SET + host 'localhost', port 6379: the client never got the URL.
// tls: false with a rediss:// provider: the URL lost its scheme on the way.

The same check for node-redis and redis-py

node-redis also falls back to localhost when url is undefined. redis-py’s Redis() with no arguments does the same, while Redis.from_url(None) raises an AttributeError and from_url("") a ValueError. Both are better than a silent fallback.

// node-redis (the "redis" package): same idea
import { createClient } from "redis";

console.log("REDIS_URL is", process.env.REDIS_URL ? "set" : "NOT SET");
const client = createClient({ url: process.env.REDIS_URL });
client.on("error", (err) => console.error("redis error:", err.code ?? err.message));
await client.connect();
console.log(await client.ping());
await client.close();

# redis-py: Redis() with no arguments means localhost:6379
import os
import redis

url = os.environ.get("REDIS_URL")
print("REDIS_URL is", "set" if url else "NOT SET")
r = redis.Redis.from_url(url) if url else redis.Redis()
kw = r.connection_pool.connection_kwargs
print(kw.get("host"), kw.get("port"), r.connection_pool.connection_class.__name__)  # SSLConnection for rediss://
print(r.ping())

Don’t connect at build time or on import

A client created at the top of a module connects as soon as anything imports that module. Frameworks import your server code during the build (Next.js does when it collects page data), and builds usually have neither the runtime variables nor the private network. Create the client on first use instead:

// lib/redis.js: importing this file opens no connection
import Redis from "ioredis";

let client;

export function redis() {
  if (!process.env.REDIS_URL) throw new Error("REDIS_URL is not set");
  client ??= new Redis(process.env.REDIS_URL);
  return client;
}

// In a route or job: await redis().get("key")
// The build can import every module; nothing dials Redis until a request needs it,
// and a missing variable fails with its name instead of ECONNREFUSED.

Platform by platform

  • Railway. Add a reference variable on your app’s service: REDIS_URL=${{Redis.REDIS_URL}}, with the name of your Redis service. If you connect to the private name from an environment made before 16 October 2025, it is IPv6 only: use family: 0 in ioredis and BullMQ. More in private networking errors.
  • Fly.io. Upstash Redis on Fly is reachable “via a private IPv6 address restricted to your Fly organization”. fly redis status prints the private URL; store it as a secret, which your app sees at run time and not during the Docker build.
  • Heroku. The first Key-Value Store add-on sets REDIS_URL and overwrites any REDIS_URL you set by hand. TLS is required; see the last row of the table.
  • Render. Every Key Value instance has an internal URL for services in the same region and an external one that you must enable first. Its examples read the internal URL from REDIS_URL. A Free web service can’t receive private network traffic, but it can send it, so it can reach Key Value.
  • Docker Compose. Each service is “discoverable by its service name”. Set REDIS_URL=redis://redis:6379 in the app service’s environment, not localhost.

BullMQ: “IMPORTANT! Eviction policy is … It should be "noeviction"”

Once it connects, BullMQ reads INFO and prints this warning when the server’s maxmemory-policy is anything else. The line in its source is IMPORTANT! Eviction policy is ${maxMemoryPolicy}. It should be "noeviction", so on Redis Cloud’s default you’d see IMPORTANT! Eviction policy is volatile-lru. It should be "noeviction".

The reason: a queue keeps jobs, locks and their metadata as ordinary keys. An eviction policy lets Redis delete keys when memory is full, so a job or a lock can disappear without an error. BullMQ’s production guide calls noeviction the only setting that guarantees the queues behave correctly. With noeviction, a full Redis refuses writes with an error instead, which you can see and fix.

Check what you have, then change it in the provider’s settings, as listed below, rather than with CONFIG SET from the app.

# What BullMQ checks, from a shell
redis-cli -u "$REDIS_URL" INFO memory | grep maxmemory_policy
maxmemory_policy:noeviction

// ...or from the app
const info = await redis.info("memory");
console.log(info.match(/maxmemory_policy:(\S+)/)?.[1]);

Which hosted Redis can run a queue

Every service we checked can be set to refuse writes instead of evicting. Two start with eviction on, and the free tiers that keep nothing on disk lose the whole queue on a restart, which BullMQ’s warning doesn’t catch. Prices and limits are in free Redis hosting compared.

ServiceDefault policySetting it to noevictionData after a restart, cheapest tier
Redis Cloud † †volatile-lruPer database, “no eviction” in the database settingsFree plan: lost, persistence is disabled. Paid Essentials: AOF every second or snapshots
Render Key Value † †You pick it when you create the instanceSelectable, and changeable later; Render recommends noeviction for job queuesFree: lost, “whenever an instance restarts, all of its data is lost”. Paid: kept on disk
Heroku Key-Value Store †noevictionAlready set; heroku redis:maxmemory changes itMini: “Persistence: None”
Upstash † †Eviction off: writes are rejected when fullAlready the case; turning eviction on uses Upstash’s own random policyKept: persistence is always on
AWS ElastiCache (node-based) †volatile-lru in the default parameter groupMake a custom parameter group; the default one can’t be editedDepends on your backup and replica settings
Railway † †The redis Docker image, so Redis’s own default: noevictionYou run it, so you set itDepends on how you run the container
Canner cachenoeviction, fixedAlready set; CONFIG is not availableKept: every write is saved to disk within a second

† Competitor details come from each vendor’s own published pages on the dates shown; prices and plans change, so check the vendor before you decide. Redis Cloud (2026-11-25) · Redis Cloud (2026-11-25) · Render Key Value (2026-11-25) · Render Key Value (2026-11-25) · Heroku Key-Value Store (2026-11-25) · Upstash (2026-11-25) · Upstash (2026-11-25) · AWS ElastiCache (node-based) (2026-11-25) · Railway (2026-11-25) · Railway (2026-11-25)

On Canner: a socket path, not a URL

Live projects can turn on a Redis-compatible cache from the project’s Services tab (Redis 7.0). After a redeploy the app gets CANNER_CACHE_SOCKET, the path of a unix socket only your app can open. There is no TCP port, so there is no redis://host:port URL, no password, and no 127.0.0.1:6379 to fall back to: give the client the path.

import Redis from "ioredis";
import { Queue, Worker } from "bullmq";

// From the Services docs: a socket path, no host, port or password.
const redis = new Redis({ path: process.env.CANNER_CACHE_SOCKET });
await redis.set("greeting", "hello", "EX", 3600);

// BullMQ passes its connection options to ioredis, so the same path works.
// maxRetriesPerRequest: null is what BullMQ asks of a Worker's connection.
const connection = { path: process.env.CANNER_CACHE_SOCKET, maxRetriesPerRequest: null };
const queue = new Queue("emails", { connection });
new Worker("emails", async (job) => sendEmail(job.data), { connection }); // your code

What the cache is, and when to use something else

  • noeviction and saved to disk. When it’s full, writes fail with OOM command not allowed when used memory > 'maxmemory'. and reads keep working. Every write reaches disk within a second, so after a restart the data is back; the last second of writes can be lost.
  • Sizes. 64 MB included with Live; 256 MB and 1 GB are add-ons (prices). Give keys an expiry: nothing is evicted to make room.
  • One project. The socket belongs to the project that turned the cache on. A web project and a separate Worker project don’t share it, so run the BullMQ worker in the same process as the app, or keep the queue in Postgres (background jobs without Redis).
  • Not available: CONFIG, DEBUG, MODULE, REPLICAOF, SLAVEOF, FAILOVER, MIGRATE, SYNC and ACL. So no modules such as search or JSON, and no clustering.
  • Use a hosted Redis instead if something outside the project must connect over TCP, if you need modules, a cluster or more than 1 GB, or if you’re on Starter.

Questions

Why does it say 127.0.0.1 when I never wrote that address?

It’s the client’s default. ioredis, node-redis, redis-py and BullMQ connect to localhost on port 6379 when they get no address, so a missing or empty REDIS_URL turns into 127.0.0.1:6379 (or ::1:6379).

It works locally and fails only after deploy. Why?

Locally, Redis is running on localhost, so the fallback works and hides the missing variable. On the server nothing listens there. Make the code throw when REDIS_URL is unset so the real problem shows up.

Why does the error appear in the build log?

Something creates the Redis client when a module is imported, and the build imports it. Builds usually have no runtime variables and no private network. Create the client on first use, or use lazyConnect: true.

Can I make BullMQ’s eviction warning go away?

Set maxmemory-policy to noeviction on the server, from the provider’s settings. Hiding the warning without changing the policy leaves your jobs open to eviction.

Does the Canner cache work with BullMQ?

Its policy is noeviction and it keeps data across restarts, which is what BullMQ asks for. Pass { path: process.env.CANNER_CACHE_SOCKET } as the connection. The queue and its workers must run in the project that owns the cache.

A cache next to your app, with no URL to lose.

On Live, turn on the cache from the Services tab, redeploy, and point your client at the socket path.