mirror of
https://github.com/jambonz/speech-utils.git
synced 2025-12-19 03:37:49 +00:00
feat: ioredis and getsize of tts cache
This commit is contained in:
23
index.js
23
index.js
@@ -1,15 +1,23 @@
|
||||
const {noopLogger} = require('./lib/utils');
|
||||
const promisify = require('@jambonz/promisify-redis');
|
||||
const redis = promisify(require('redis'));
|
||||
const Redis = require('ioredis');
|
||||
|
||||
module.exports = (opts, logger) => {
|
||||
const {host = '127.0.0.1', port = 6379, tls = false} = opts;
|
||||
logger = logger || noopLogger;
|
||||
const connectionOpts = {...opts};
|
||||
// Support legacy app
|
||||
if (process.env.JAMBONES_REDIS_USERNAME && process.env.JAMBONES_REDIS_PASSWORD) {
|
||||
if (Array.isArray(connectionOpts)) {
|
||||
for (const o of opts) {
|
||||
o.username = process.env.JAMBONES_REDIS_USERNAME;
|
||||
o.password = process.env.JAMBONES_REDIS_PASSWORD;
|
||||
}
|
||||
} else {
|
||||
connectionOpts.username = process.env.JAMBONES_REDIS_USERNAME;
|
||||
connectionOpts.password = process.env.JAMBONES_REDIS_PASSWORD;
|
||||
}
|
||||
}
|
||||
|
||||
const url = process.env.JAMBONES_REDIS_USERNAME && process.env.JAMBONES_REDIS_PASSWORD ?
|
||||
`${process.env.JAMBONES_REDIS_USERNAME}:${process.env.JAMBONES_REDIS_PASSWORD}@${host}:${port}` :
|
||||
`${host}:${port}`;
|
||||
const client = redis.createClient(tls ? `rediss://${url}` : `redis://${url}`);
|
||||
const client = new Redis(connectionOpts);
|
||||
['ready', 'connect', 'reconnecting', 'error', 'end', 'warning']
|
||||
.forEach((event) => {
|
||||
client.on(event, (...args) => {
|
||||
@@ -23,6 +31,7 @@ module.exports = (opts, logger) => {
|
||||
|
||||
return {
|
||||
client,
|
||||
getTtsSize: require('./lib/get-tts-size').bind(null, client, logger),
|
||||
purgeTtsCache: require('./lib/purge-tts-cache').bind(null, client, logger),
|
||||
synthAudio: require('./lib/synth-audio').bind(null, client, logger),
|
||||
getNuanceAccessToken: require('./lib/get-nuance-access-token').bind(null, client, logger),
|
||||
|
||||
Reference in New Issue
Block a user