Skip to content

Commit c1ca9ca

Browse files
committed
feat: add support for rediss protocol in url
1 parent 0094795 commit c1ca9ca

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ using unix sockets if possible to increase throughput.
216216
| host | 127.0.0.1 | IP address of the Redis server |
217217
| port | 6379 | Port of the Redis server |
218218
| path | null | The UNIX socket string of the Redis server |
219-
| url | null | The URL of the Redis server. Format: `[redis:]//[[user][:password@]][host][:port][/db-number][?db=db-number[&password=bar[&option=value]]]` (More info avaliable at [IANA](http://www.iana.org/assignments/uri-schemes/prov/redis)). |
219+
| url | null | The URL of the Redis server. Format: `[redis:][rediss:]//[[user][:password@]][host][:port][/db-number][?db=db-number[&password=bar[&option=value]]]` (More info avaliable at [IANA](http://www.iana.org/assignments/uri-schemes/prov/redis)). |
220220
| parser | javascript | __Deprecated__ Use either the built-in JS parser [`javascript`]() or the native [`hiredis`]() parser. __Note__ `node_redis` < 2.6 uses hiredis as default if installed. This changed in v.2.6.0. |
221221
| string_numbers | null | Set to `true`, `node_redis` will return Redis number values as Strings instead of javascript Numbers. Useful if you need to handle big numbers (above `Number.MAX_SAFE_INTEGER === 2^53`). Hiredis is incapable of this behavior, so setting this option to `true` will result in the built-in javascript parser being used no matter the value of the `parser` option. |
222222
| return_buffers | false | If set to `true`, then all replies will be sent to callbacks as Buffers instead of Strings. |

lib/createClient.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ module.exports = function createClient (port_arg, host_arg, options) {
3232
options.password = parsed.auth.split(':')[1];
3333
}
3434
if (parsed.protocol && parsed.protocol !== 'redis:') {
35-
console.warn('node_redis: WARNING: You passed "' + parsed.protocol.substring(0, parsed.protocol.length - 1) + '" as protocol instead of the "redis" protocol!');
35+
if (parsed.protocol === 'rediss:') {
36+
options.tls = options.tls || {};
37+
} else {
38+
console.warn('node_redis: WARNING: You passed "' + parsed.protocol.substring(0, parsed.protocol.length - 1) + '" as protocol instead of the "redis" protocol!');
39+
}
3640
}
3741
if (parsed.pathname && parsed.pathname !== '/') {
3842
options.db = parsed.pathname.substr(1);

test/tls.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,29 @@ describe('TLS connection tests', function () {
108108
client.get('foo', helper.isString('bar', done));
109109
});
110110

111+
describe('using rediss as url protocol', function (done) {
112+
var tls = require('tls')
113+
var tlsConnect = tls.connect
114+
beforeEach(function () {
115+
tls.connect = function (options) {
116+
options = utils.clone(options)
117+
options.ca = tls_options.ca;
118+
return tlsConnect.call(tls, options);
119+
}
120+
})
121+
afterEach(function () {
122+
tls.connect = tlsConnect;
123+
})
124+
it('connect with tls when rediss is used as the protocol', function (done) {
125+
if (skip) this.skip();
126+
client = redis.createClient('rediss://localhost:' + tls_port);
127+
// verify connection is using TCP, not UNIX socket
128+
assert(client.stream.encrypted);
129+
client.set('foo', 'bar');
130+
client.get('foo', helper.isString('bar', done));
131+
});
132+
})
133+
111134
it('fails to connect because the cert is not correct', function (done) {
112135
if (skip) this.skip();
113136
var faulty_cert = utils.clone(tls_options);

0 commit comments

Comments
 (0)