Skip to content

Commit

Permalink
fix(lua): Expose unpack to imitate redis's lua 5.1 support
Browse files Browse the repository at this point in the history
In lua 5.2, the global function unpack was moved to table.unpack.

closes stipsan#1193
  • Loading branch information
TysonAndre-tmg authored and stipsan committed Jan 29, 2023
1 parent 9213bc7 commit 1ecf881
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/commands/defineCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const defineRedisObject = vm => fn => {
end
return val
end
unpack = table.unpack
redis.call = function(...)
return repair(call(false, ...))
end
Expand Down
11 changes: 11 additions & 0 deletions test/integration/commands/eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 1ecf881

Please sign in to comment.