From 1ecf881dbf10a1c9164806659d09f07bb72f3677 Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Fri, 15 Jul 2022 16:17:30 -0400 Subject: [PATCH] fix(lua): Expose unpack to imitate redis's lua 5.1 support In lua 5.2, the global function unpack was moved to table.unpack. closes #1193 --- src/commands/defineCommand.js | 1 + test/integration/commands/eval.js | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/commands/defineCommand.js b/src/commands/defineCommand.js index 946b3db8a..cc206b4d6 100644 --- a/src/commands/defineCommand.js +++ b/src/commands/defineCommand.js @@ -27,6 +27,7 @@ export const defineRedisObject = vm => fn => { end return val end + unpack = table.unpack redis.call = function(...) return repair(call(false, ...)) end diff --git a/test/integration/commands/eval.js b/test/integration/commands/eval.js index ce612c178..a30a0cce3 100644 --- a/test/integration/commands/eval.js +++ b/test/integration/commands/eval.js @@ -17,6 +17,17 @@ runTwinSuite('eval', (command, equals) => { expect(equals(retVal, 'hello')).toBe(true) }) + it('should support unpack', async () => { + const luaScript = ` + function sum(a, b) + return tonumber(a)+tonumber(b) + end + return sum(unpack(ARGV))` + const retVal = await redis[command](luaScript, 0, 2, 12) + + expect(retVal).toEqual(14) + }) + it('should execute a lua script through eval and get the return value', () => { const NUMBER_OF_KEYS = 2 const KEY1 = 'KEY1'