-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #9 This commit offers a cleanup to unify the redis client usage and add an error handler to handle redis connection errors. The option for offline queue has been removed (for now) as it may grow the callback queue to infinity and eventually result in a RangeError.
- Loading branch information
1 parent
b2760ba
commit da09106
Showing
3 changed files
with
38 additions
and
32 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
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,20 @@ | ||
import Redis from 'ioredis'; | ||
|
||
/** | ||
* Creates a new Redis client instance | ||
* @param {object} config - redis configuration | ||
* @param {Werelogs} log - Werelogs logger | ||
* @return {Redis} - Redis client instance | ||
*/ | ||
export default function redisClient(config, log) { | ||
const redisClient = new Redis(Object.assign({ | ||
// disable offline queue | ||
enableOfflineQueue: false, | ||
// keep alive 3 seconds | ||
keepAlive: 3000, | ||
}, config)); | ||
redisClient.on('error', err => log.trace('error with redis client', { | ||
error: err, | ||
})); | ||
return redisClient; | ||
} |