Registry / database / redis-url

redis-url

JSON →
library1.2.1jsnpmunverified

Connect to Redis using a fully-qualified URL. This package (v1.2.1, last released in 2015) provides a simple connect() wrapper around node_redis that parses the REDIS_URL environment variable or a custom URL, returning a redis client. It also exposes a parse() function that extends Node's url.parse with database and password properties. Unlike ioredis or modern node_redis, this library does not support Redis Cluster, TLS, or advanced features. It is stable but effectively in maintenance mode, as the underlying redis client is outdated. Suitable for legacy projects or simple use cases where only basic Redis connectivity via URL is needed.

npm install redis-url
INSTALL
IMPORT
SIG · REDIS-URL
R
redis-url
databasejavascriptv1.2.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

connect
var redis = require('redis-url').connect(url);
import { connect } from 'redis-url';
Package uses CommonJS require() and does not provide ES module exports. The returned object from connect() is a redis client (node_redis).
parse
var parsed = require('redis-url').parse(url);
import { parse } from 'redis-url';
Parse function returns an object with password and database properties in addition to standard url.parse output. No TypeScript types provided.
default import
var redisUrl = require('redis-url'); var client = redisUrl.connect();
var redisUrl = require('redis-url').default;
There is no default export. The module exports an object with connect and parse methods.

Initialize a Redis client from a URL string (or env var), set and get a key, then gracefully close the connection.

// Ensure you have a redis server running and have installed dependencies: // npm install redis-url redis var redisUrl = require('redis-url'); var url = process.env.REDIS_URL || 'redis://localhost:6379'; var client = redisUrl.connect(url); client.on('connect', function() { console.log('Connected to Redis'); client.set('foo', 'bar', function(err, reply) { console.log('Set reply:', reply); client.get('foo', function(err, value) { console.log('Got value:', value); client.quit(); }); }); }); client.on('error', function(err) { console.error('Redis error:', err); });
Debug
Known issues
deprecatedThe underlying 'redis' client (node_redis) has breaking changes in v3+. redis-url was not updated to support them and may produce errors or unexpected behavior.
fix
Use ioredis or modern node_redis directly: `const Redis = require('ioredis'); const client = new Redis(url);`
affects: >=1.0.0
gotchaconnect() ignores URL query parameters for TLS/SSL options. To enable TLS, you must pass extra options to the underlying node_redis (not supported by redis-url).
fix
Use a library that supports redis:// URL parsing with TLS, or manually create a Redis client with tls option.
affects: >=1.0.0
gotchapassword and database from parse() may be undefined if not present in URL; they are strings when present. Database number is a string, not integer.
fix
Convert database to integer: parseInt(parsed.database, 10) || 0
affects: >=1.0.0
gotchaThe package uses the deprecated redis client version (0.7.x-1.x). It may not support newer Redis features (cluster, sentinel, RESP3).
fix
Migrate to ioredis or redis v4 which have built-in URL parsing.
affects: >=1.0.0
deprecatedparse() returns query as an object (if query string exists) but does not guarantee behavior for duplicate keys.
fix
Use Node's built-in url.parse() or URL constructor with searchParams for robust query parsing.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: redis_url.connect is not a function
Using ES module import syntax (e.g., import { connect } from 'redis-url') which this package does not support.
fix
Use require('redis-url').connect() instead of ES import.
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
Redis server is not running or not accessible at the specified URL/host.
fix
Start the Redis server (e.g., `redis-server &`). Verify the URL is correct and the server is listening.
Error: ERR invalid password
The password in the URL is incorrect or the Redis server requires authentication but none was provided.
fix
Check the URL for correct password: redis://:correctpassword@host:port/db
TypeError: Cannot read property 'port' of undefined
Calling parse() on a non-string or malformed URL.
fix
Ensure the URL argument to parse() is a valid string (e.g., 'redis://localhost:6379').
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies
redisrequiredPeer dependency: uses the node_redis library (v0.7.x-1.x) to create client connections. Must be installed separately.
node-uuidoptionalUsed for unique identifier generation in older versions; may not be needed in latest release.
Agent activity
13 hits · last 30 days
node
12
Resources
redis-url — npm install redis-url · libregistry