-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '4.x' into transloadit-single-assembly
* 4.x: @uppy/companion: switch from `node-redis` to `ioredis` (#4623) Fix headings in xhr.mdx
- Loading branch information
Showing
9 changed files
with
131 additions
and
127 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,34 @@ | ||
const redis = require('redis') | ||
const Redis = require('ioredis').default | ||
|
||
const logger = require('./logger') | ||
|
||
/** @type {import('ioredis').Redis} */ | ||
let redisClient | ||
|
||
/** | ||
* A Singleton module that provides a single redis client through out | ||
* the lifetime of the server | ||
* | ||
* @param {{ redisUrl?: string, redisOptions?: Record<string, any> }} [companionOptions] options | ||
* @param {string} [redisUrl] ioredis url | ||
* @param {Record<string, any>} [redisOptions] ioredis client options | ||
*/ | ||
function createClient (companionOptions) { | ||
function createClient (redisUrl, redisOptions) { | ||
if (!redisClient) { | ||
const { redisUrl, redisOptions } = companionOptions | ||
redisClient = redis.createClient({ | ||
...redisOptions, | ||
...(redisUrl && { url: redisUrl }), | ||
}) | ||
|
||
redisClient.on('error', err => logger.error('redis error', err)) | ||
|
||
;(async () => { | ||
try { | ||
// fire and forget. | ||
// any requests made on the client before connection is established will be auto-queued by node-redis | ||
await redisClient.connect() | ||
} catch (err) { | ||
logger.error(err.message, 'redis.error') | ||
} | ||
})() | ||
if (redisUrl) { | ||
redisClient = new Redis(redisUrl, redisOptions) | ||
} else { | ||
redisClient = new Redis(redisOptions) | ||
} | ||
redisClient.on('error', err => logger.error('redis error', err.toString())) | ||
} | ||
|
||
return redisClient | ||
} | ||
|
||
module.exports.client = (companionOptions) => { | ||
if (!companionOptions?.redisUrl && !companionOptions?.redisOptions) { | ||
module.exports.client = ({ redisUrl, redisOptions } = { redisUrl: undefined, redisOptions: undefined }) => { | ||
if (!redisUrl && !redisOptions) { | ||
return redisClient | ||
} | ||
|
||
return createClient(companionOptions) | ||
return createClient(redisUrl, redisOptions) | ||
} |
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.