Registry / database / redis-url-plus

redis-url-plus

JSON →
library1.2.1jsnpmunverified

A Redis connection string parser that supports standalone, cluster, sentinel, and Unix socket URLs, aligning with Redis-CLI command formats. Current stable version is 1.2.1. The library handles multiple Redis URL syntaxes in a single call, returning structured objects with host, port, db, password, and cluster node arrays. It supports Node 10+. Key differentiators: built-in cluster detection (redis-cluster://) and sentinel support (redis-sentinel://) with master name parsing, unlike simpler parsers.

npm install redis-url-plus
INSTALL
IMPORT
SIG · REDIS-URL-PLUS
R
redis-url-plus
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.

RedisUrlParser
import RedisUrlParser from 'redis-url-plus'
const RedisUrlParser = require('redis-url-plus').default
CommonJS require works as shown in README, but ESM users should use default import (the module uses module.exports = function, so ESM default import is correct).
default export
const parse = require('redis-url-plus')
const { parse } = require('redis-url-plus')
The module exports a single function directly via module.exports. Named destructuring will result in undefined.
type inferrence (TypeScript)
import RedisUrlParser from 'redis-url-plus'; const result = RedisUrlParser('redis://localhost:6379/0'); // result is automatically inferred as RedisUrlResult | RedisClusterResult | ...
const result: any = RedisUrlParser(...)
TypeScript definitions are included in the package; avoid manually typing the result. The library exports union types for standalone/cluster/sentinel/socket results.

Demonstrates parsing standalone, cluster, sentinel, and Unix socket Redis URLs using redis-url-plus.

import RedisUrlParser from 'redis-url-plus'; const standaloneUrl = 'redis://user:pass@localhost:6379/0'; const result = RedisUrlParser(standaloneUrl); console.log(result); // { // password: 'pass', // db: 0, // port: 6379, // host: 'localhost' // } const clusterUrl = 'redis-cluster://localhost:6379,localhost:6380'; const clusterResult = RedisUrlParser(clusterUrl); console.log(clusterResult); // { // cluster: true, // nodes: [ // { host: 'localhost', port: 6379 }, // { host: 'localhost', port: 6380 } // ] // } const sentinelUrl = 'redis-sentinel://sentinel:26379/mymaster/0'; const sentinelResult = RedisUrlParser(sentinelUrl); console.log(sentinelResult); // { // db: 0, // name: 'mymaster', // sentinels: [{ host: 'sentinel', port: 26379 }] // } const socketUrl = 'socket://tmp/redis.sock'; const socketResult = RedisUrlParser(socketUrl); console.log(socketResult); // { path: '/tmp/redis.sock' }
Debug
Known issues
gotchaThe parser treats URLs with multiple comma-separated hosts as cluster nodes only if the scheme is 'redis-cluster://'. For 'redis://' with multiple hosts, it also returns a cluster object with nodes array. Mixing schemes (e.g., 'redis://...' and 'redis-cluster://...') is undefined.
fix
Ensure you use the correct scheme: 'redis://' for standalone or multiple standalone nodes (no cluster flag), 'redis-cluster://' for explicit cluster mode. When using 'redis://' with multiple hosts separated by comma, the library will return a result with cluster: true and nodes array (undocumented but observed).
affects: >=1.0.0
gotchaSentinel URLs (redis-sentinel://) must include a master name as first path segment after host:port. Omitting it results in undefined behavior.
fix
Always include the master name in the sentinel URL: redis-sentinel://host:port/master_name/db
affects: >=1.0.0
deprecatedNode.js 10 and 12 are no longer officially supported by the Node.js project. This library may still work, but it is recommended to use Node 14+.
fix
Update Node.js to version 14 or later.
affects: >=1.2.1
gotchaThe library parses the URL query string? No query string support is documented. All parameters must be in the URL path or userinfo.
fix
Use standard Redis URL format: redis://user:pass@host:port/db. Do not rely on query parameters.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'redis-url-plus'
The package is not installed, or the import path is incorrect.
fix
Run `npm install redis-url-plus` or `yarn add redis-url-plus`. Ensure the package is in node_modules.
TypeError: RedisUrlParser is not a function
Using ES import syntax incorrectly when the module uses CommonJS export.
fix
Use default import: `import RedisUrlParser from 'redis-url-plus'` or CommonJS require: `const RedisUrlParser = require('redis-url-plus')`.
undefined is not an object (evaluating 'result.host')
Parsing a malformed URL that does not match any known pattern, returning an unexpected object shape.
fix
Ensure the URL is valid: use one of the supported formats (redis://, redis-cluster://, redis-sentinel://, socket://). Check for typos.
Property 'cluster' does not exist on type '...' (TypeScript)
TypeScript type narrowing not applied; the result type is a union and TypeScript can't narrow without explicit check.
fix
Use type guard: `if ('cluster' in result && result.cluster) { ... }` or cast appropriately.
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
redis-url-plus — npm install redis-url-plus · libregistry