1.2.1 • Published 2 months ago

redis-url-plus v1.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

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