Skip to content

Redis Connect URL parser aligned with Redis-CLI commands

Notifications You must be signed in to change notification settings

rickyes/redis-url-plus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redis-url-plus

NPM version Codacy build status Test coverage npm downloads/month npm downloads

Redis Connect URL parser aligned with Redis-CLI commands

Features

  1. Standalone
  2. Cluster
  3. Sentinel
  4. Unix Domain Socket

Install

$ yarn add redis-url-plus
# or
$ npm i redis-url-plus

Usage

# standalone/cluster
redis://username:password@host:port/db[,redis://username:password@host:port/db]

# sentinel
redis-sentinel://[username:password@]host:port[,host:port]/master_name/db

# unix domain socket
socket://tmp/redis.sock

# cluster
redis-cluster://host:port[,host:port]
const RedisUrlParser = require('redis-url-plus');

RedisUrlParser('redis://localhost:6379/0');

// redis://localhost:6379/0 ==> { password: '', db: 0, port: 6379, host: 'localhost' }
// redis://localhost:6379, ==> { password: '', db: 0, port: 6379, host: 'localhost' }
// redis://user:pass@localhost:6379, ==> { password: 'pass', db: 0, port: 6379, host: 'localhost' }
/**
 * redis://localhost:6379,redis://localhost:6378,redis://localhost:6377
 *
 * ||
 * 
 * {
 *   cluster: true,
 *     nodes: [
 *      { password: '', db: 0, port: 6379, host: 'localhost' },
 *      { password: '', db: 0, port: 6378, host: 'localhost' },
 *      { password: '', db: 0, port: 6377, host: 'localhost' }
 *    ]
 * }
 **/

// redis-sentinel://sentinel:26379/mymaster/0 ==> { db: 0, name: 'mymaster', sentinels: [{ host: 'sentinel', port: 26379 }] }
/**
 * 
 * redis-sentinel://usr:pwd@sentinel:26379/mymaster/0
 * 
 * ||
 * 
 * { username: 'usr', password: 'pwd', db: 0, name: 'mymaster', sentinels: [{ host: 'sentinel', port: 26379 }] }
 *  
 **/

// socket://tmp/redis.sock ==> { path: '/tmp/redis.sock' }

// redis-cluster://localhost:6379 ==> { cluster: true, nodes: [{ host: 'localhost', port: 6379 }] }
/**
 * 
 * redis-cluster://localhost:6379,localhost:6380
 * 
 * ||
 * 
 * { cluster: true, nodes: [{ host: 'localhost', port: 6379 }, { host: 'localhost', port: 6380 }] }
 *  
 **/

Support Version

  • 10
  • 12
  • 14
  • 16

About

Redis Connect URL parser aligned with Redis-CLI commands

Resources

Stars

Watchers

Forks

Packages

No packages published