Skip to content

Commit 371bb9c

Browse files
monkbrocluin
authored andcommitted
feat: support rediss:// URL
1 parent fd25e89 commit 371bb9c

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ new Redis({
120120
});
121121
```
122122

123-
You can also specify connection options as a [`redis://` URL](http://www.iana.org/assignments/uri-schemes/prov/redis):
123+
You can also specify connection options as a [`redis://` URL](http://www.iana.org/assignments/uri-schemes/prov/redis) or [`rediss://` URL](https://www.iana.org/assignments/uri-schemes/prov/rediss) when using [TLS encryption](#tls-options):
124124

125125
```javascript
126126
// Connect to 127.0.0.1:6380, db 4, using password "authpassword":
@@ -703,6 +703,12 @@ var redis = new Redis({
703703
});
704704
```
705705

706+
Alternatively, specify the connection through a [`rediss://` URL](https://www.iana.org/assignments/uri-schemes/prov/rediss).
707+
708+
```javascript
709+
var redis = new Redis("rediss://redis.my-service.com");
710+
```
711+
706712
<hr>
707713

708714
## Sentinel

lib/redis/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ var debug = Debug("redis");
110110
* var unixSocketRedis2 = new Redis('/tmp/echo.sock');
111111
* var urlRedis = new Redis('redis://user:[email protected]:6379/');
112112
* var urlRedis2 = new Redis('//localhost:6379');
113+
* var urlRedisTls = new Redis('rediss://user:[email protected]:6379/');
113114
* var authedRedis = new Redis(6380, '192.168.100.1', { password: 'password' });
114115
* ```
115116
*/

lib/utils/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export function parseURL(url) {
260260
result.password = parsed.auth.split(":")[1];
261261
}
262262
if (parsed.pathname) {
263-
if (parsed.protocol === "redis:") {
263+
if (parsed.protocol === "redis:" || parsed.protocol === "rediss:") {
264264
if (parsed.pathname.length > 1) {
265265
result.db = parsed.pathname.slice(1);
266266
}
@@ -274,6 +274,9 @@ export function parseURL(url) {
274274
if (parsed.port) {
275275
result.port = parsed.port;
276276
}
277+
if (parsed.protocol === "rediss:") {
278+
result.tls = true;
279+
}
277280
defaults(result, parsed.query);
278281

279282
return result;

test/unit/utils.ts

+10
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,16 @@ describe("utils", function() {
192192
expect(utils.parseURL("redis://127.0.0.1/")).to.eql({
193193
host: "127.0.0.1"
194194
});
195+
expect(
196+
utils.parseURL("rediss://user:[email protected]:6380/4?key=value")
197+
).to.eql({
198+
tls: true,
199+
host: "127.0.0.1",
200+
port: "6380",
201+
db: "4",
202+
password: "pass",
203+
key: "value"
204+
});
195205
});
196206
});
197207

0 commit comments

Comments
 (0)