redis-url-parse
v2.0.0
Published
Spread a Redis URL string into a configuration object.
Downloads
14,940
Readme
Redis URL Parse
Spread a Redis URL string into a configuration object.
Module usage
const redisUrlParse = require('redis-url-parse')
// Defaults to localhost:6379/0
redisUrlParse('redis://')
//=> {host: 'localhost', port: 6379, database: '0', password: undefined}
// But you can change databases by adding a path
redisUrlParse('redis:///1')
//=> {host: 'localhost', port: 6379, database: '1', password: undefined}
// And change hosts
redisUrlParse('redis://example.com:39143/')
//=> {host: 'example.com', port: 39143, database: '0', password: undefined}
// And even add passwords
redisUrlParse('redis://:[email protected]:39143/')
//=> {host: 'example.com', port: 39143, database: '0', password: 'n9y25ah7'}
// If you add a username, it's ignored
redisUrlParse('redis://user:[email protected]:39143/')
//=> {host: 'example.com', port: 39143, database: '0', password: 'hunter2'}
// If your password uses special characters, you may need to URI encode it
redisUrlParse('redis://:my%3Asuper%21secure%[email protected]:39143/')
//=> {host: 'example.com', port: 39143, database: '0', password: 'my:super!secure?password'}
Complete example
const redisUrlParse = require('redis-url-parse')
redisUrlParse(process.env.REDIS_URL) // redis://
//=> {host: 'localhost', port: 6379, database: '0', password: undefined}
Prior art
- parse-redis-url not maintained and has an extremely awkward interface
require('parse-redis-url')(null).parse(url)
- redis-url not maintained and requires
redis
as a requirement - redis-url-parser not maintained and only works if your URL has a password