Skip to content

Commit

Permalink
fix(lua): Expose unpack to imitate redis's lua 5.1 support (#1194)
Browse files Browse the repository at this point in the history
Co-authored-by: Tyson Andre <[email protected]>
Fixes #1193
  • Loading branch information
TysonAndre authored Jan 29, 2023
1 parent 1537301 commit df83646
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 df83646

Please sign in to comment.