* Load redis lua scripts. * The name of the script must have the following format: * * cmdName-numKeys.lua * * cmdName must be in camel case format. * * For example: * moveToFinish-3.lua *
(dir, cache)
| 357 | * |
| 358 | */ |
| 359 | async loadScripts(dir, cache) { |
| 360 | dir = path.normalize(dir || __dirname); |
| 361 | |
| 362 | let commands = this.commandCache.get(dir); |
| 363 | if (commands) { |
| 364 | return commands; |
| 365 | } |
| 366 | |
| 367 | const files = await readdir(dir); |
| 368 | |
| 369 | const luaFiles = files.filter(file => path.extname(file) === '.lua'); |
| 370 | |
| 371 | if (luaFiles.length === 0) { |
| 372 | /** |
| 373 | * To prevent unclarified runtime error "updateDelayset is not a function |
| 374 | * @see https://github.com/OptimalBits/bull/issues/920 |
| 375 | */ |
| 376 | throw new ScriptLoaderError('No .lua files found!', dir, []); |
| 377 | } |
| 378 | |
| 379 | commands = []; |
| 380 | cache = cache ? cache : new Map(); |
| 381 | |
| 382 | for (let i = 0; i < luaFiles.length; i++) { |
| 383 | const file = path.join(dir, luaFiles[i]); |
| 384 | |
| 385 | const command = await this.loadCommand(file, cache); |
| 386 | commands.push(command); |
| 387 | } |
| 388 | |
| 389 | this.commandCache.set(dir, commands); |
| 390 | |
| 391 | return commands; |
| 392 | } |
| 393 | |
| 394 | /** |
| 395 | * Attach all lua scripts in a given directory to a client instance |
no test coverage detected