Redis Connect URL parser aligned with Redis-CLI commands
- Standalone
- Cluster
- Sentinel
- Unix Domain Socket
$ yarn add redis-url-plus
# or
$ npm i redis-url-plus
# 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 }] }
*
**/
- 10
- 12
- 14
- 16