UNPKG

@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:

31 lines (30 loc) 966 B
"use strict"; 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 {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; } module.exports.client = ({ redisUrl, redisOptions } = { redisUrl: undefined, redisOptions: undefined }) => { if (!redisUrl && !redisOptions) { return redisClient; } return createClient(redisUrl, redisOptions); };