-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom connectors and additional typings #906
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
0240a4f
refactor sentinel iterator for type
imatlopez 9a0ff64
Add connectToFloat
imatlopez a2c04cd
error on float no sentinels
imatlopez 9372906
logic error
imatlopez 367c12c
fix TypeError
imatlopez d237c0b
make iterator work inplace for tests
imatlopez f39bda0
fix tertiary flip
imatlopez 6aaca84
pass through connector
imatlopez 4411710
Use promises for simpler interface
imatlopez ba2ad7c
remove hanging spaces
imatlopez 7605011
change typings for async
imatlopez 0fb5c88
add build to travis to test build and made ts errors quiet for tests
imatlopez c040ba1
Fix bad connector reference
imatlopez 27efcb7
callback → promise connect
imatlopez 7f5f592
Fix more `this`
imatlopez adae66a
fix hanging promise
imatlopez 9e8bded
another unhooked promise
imatlopez f6c4ab8
move to examples
imatlopez 678ab98
one more bad resolve
imatlopez 9e43e47
take a step back
imatlopez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ | ||
{ | ||
"env": { | ||
"node": true | ||
"node": true, | ||
"es6": true | ||
}, | ||
"rules": { | ||
"no-const-assign": 2, | ||
|
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,53 @@ | ||
'use strict'; | ||
|
||
const Redis = require('ioredis'); | ||
const MyService = require('path/to/my/service'); | ||
|
||
// Create a custom connector that fetches sentinels from an external call | ||
class AsyncSentinelConnector extends Redis.SentinelConnector { | ||
constructor(options = {}) { | ||
// Placeholder | ||
options.sentinels = options.sentinels || [{ host: 'localhost', port: 6379 }]; | ||
|
||
// SentinelConnector saves options as its property | ||
super(options); | ||
} | ||
|
||
connect(eventEmitter) { | ||
return MyService.getSentinels().then(sentinels => { | ||
this.options.sentinels = sentinels; | ||
this.sentinelIterator = new Redis.SentinelIterator(sentinels); | ||
return Redis.SentinelConnector.prototype.connect.call(this, eventEmitter); | ||
}); | ||
} | ||
} | ||
|
||
const redis = new Redis({ | ||
connector: new AsyncSentinelConnector() | ||
}); | ||
|
||
// ioredis supports all Redis commands: | ||
redis.set('foo', 'bar'); | ||
redis.get('foo', function (err, result) { | ||
if (err) { | ||
console.error(err); | ||
} else { | ||
console.log(result); | ||
} | ||
}); | ||
redis.del('foo'); | ||
|
||
// Or using a promise if the last argument isn't a function | ||
redis.get('foo').then(function (result) { | ||
console.log(result); | ||
}); | ||
|
||
// Arguments to commands are flattened, so the following are the same: | ||
redis.sadd('set', 1, 3, 5, 7); | ||
redis.sadd('set', [1, 3, 5, 7]); | ||
|
||
// All arguments are passed directly to the redis server: | ||
redis.set('key', 100, 'EX', 10); | ||
|
||
// Change the server configuration | ||
redis.config('set', 'notify-keyspace-events', 'KEA'); |
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why
npm run build
is needed here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test may have type errors like trying to access private properties, but the code itself is fine, so this guards against build time errors while the tests are for logical errors only.