-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: nat support for sentinel connector (#799)
- Loading branch information
Showing
4 changed files
with
92 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
node_modules | ||
*.cpuprofile | ||
/test.js | ||
/.idea | ||
built | ||
|
||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
describe('sentinel_nat', function() { | ||
it('connects to server as expected', function(done) { | ||
|
||
var sentinel = new MockServer(27379, function (argv) { | ||
if (argv[0] === 'sentinel' && argv[1] === 'get-master-addr-by-name') { | ||
return ['127.0.0.1', '17380']; | ||
} | ||
}) | ||
|
||
var redis = new Redis({ | ||
sentinels: [ | ||
{ host: '127.0.0.1', port: '27379' } | ||
], | ||
natMap: { | ||
'127.0.0.1:17380': { | ||
host: 'localhost', | ||
port: 6379, | ||
} | ||
}, | ||
name: 'master', | ||
lazyConnect: true, | ||
}) | ||
|
||
redis.connect(function(err) { | ||
if (err) { | ||
sentinel.disconnect(function() {}) | ||
return done(err) | ||
} | ||
sentinel.disconnect(done) | ||
}) | ||
}) | ||
|
||
it('rejects connection if host is not defined in map', function(done) { | ||
var sentinel = new MockServer(27379, function (argv) { | ||
if (argv[0] === 'sentinel' && argv[1] === 'get-master-addr-by-name') { | ||
return ['127.0.0.1', '17380'] | ||
} | ||
|
||
if (argv[0] === 'sentinel' && argv[1] === 'sentinels' &&argv[2] === 'master') { | ||
return ['127.0.0.1', '27379'] | ||
} | ||
}) | ||
|
||
var redis = new Redis({ | ||
sentinels: [ | ||
{ host: '127.0.0.1', port: '27379' } | ||
], | ||
natMap: { | ||
'127.0.0.1:17381': { | ||
host: 'localhost', | ||
port: 6379, | ||
} | ||
}, | ||
maxRetriesPerRequest: 1, | ||
name: 'master', | ||
lazyConnect: true, | ||
}) | ||
|
||
redis | ||
.connect() | ||
.then(function() { | ||
throw new Error("Should not call") | ||
}) | ||
.catch(function(err) { | ||
if (err.message === 'Connection is closed.') { | ||
return done(null) | ||
} | ||
sentinel.disconnect(done) | ||
}) | ||
}) | ||
|
||
}) |