@uppy/companion
Version:
OAuth helper and remote fetcher for Uppy's (https://uppy.io) extensible file upload widget with support for drag&drop, resumable uploads, previews, restrictions, file processing/encoding, remote providers like Dropbox and Google Drive, S3 and more :dog:
38 lines (32 loc) • 901 B
JavaScript
import { Redis } from 'ioredis'
import * as logger from './logger.js'
/** @type {import('ioredis').Redis} */
let redisClient
/**
* A Singleton module that provides a single redis client through out
* the lifetime of the server
*
* @param {string} [redisUrl] ioredis url
* @param {Record<string, any>} [redisOptions] ioredis client options
*/
function createClient(redisUrl, redisOptions) {
if (!redisClient) {
if (redisUrl) {
redisClient = new Redis(redisUrl, redisOptions)
} else {
redisClient = new Redis(redisOptions)
}
redisClient.on('error', (err) =>
logger.error('redis error', err.toString()),
)
}
return redisClient
}
export function client(
{ redisUrl, redisOptions } = { redisUrl: undefined, redisOptions: undefined },
) {
if (!redisUrl && !redisOptions) {
return redisClient
}
return createClient(redisUrl, redisOptions)
}