Skip to content

Commit 30d2184

Browse files
author
Ruben Bridgewater
committed
Throw on other protocols provided than the redis protocol
1 parent bc85c4a commit 30d2184

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,9 @@ var createClient = function (port_arg, host_arg, options) {
12701270
if (parsed.auth) {
12711271
options.auth_pass = parsed.auth.split(':')[1];
12721272
}
1273+
if (parsed.protocol !== 'redis:') {
1274+
throw new Error('Connection string must use the "redis:" protocol');
1275+
}
12731276
options.host = parsed.hostname;
12741277
options.port = parsed.port;
12751278
} else {

test/connection.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,18 @@ describe("connection tests", function () {
307307
}
308308
});
309309

310+
it("throws on protocol other than redis in the redis url", function () {
311+
client = {
312+
end: function() {}
313+
};
314+
try {
315+
redis.createClient(config.HOST[ip] + ':' + config.PORT);
316+
throw new Error('failed');
317+
} catch (err) {
318+
assert.equal(err.message, 'Connection string must use the "redis:" protocol');
319+
}
320+
});
321+
310322
if (ip === 'IPv4') {
311323
it('allows connecting with the redis url and the default port', function (done) {
312324
client = redis.createClient('redis://foo:porkchopsandwiches@' + config.HOST[ip]);

0 commit comments

Comments
 (0)