Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.3.1] - not released
### Added
- Added support for `unpack` as an alias for `table.unpack` to ensure compatability for old lua scripts running on new lua versions (> 5.1).

## [0.3.0] - 2024-10-15
### Changed
- Use Digest::SHA1 instead of Digest::SHA256 for hex_digest.
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
mock_redis_lua_extension2 (0.3.0)
mock_redis_lua_extension2 (0.3.1.pre.0)
mock_redis
rufus-lua

Expand All @@ -10,7 +10,7 @@ GEM
specs:
coderay (1.1.3)
diff-lcs (1.3)
ffi (1.17.0)
ffi (1.17.1)
method_source (1.1.0)
mock_redis (0.28.0)
ruby2_keywords
Expand Down
2 changes: 2 additions & 0 deletions lib/mock_redis_lua_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def eval(script, keys=nil, argv=nil, **args)
lua_state = Rufus::Lua::State.new
setup_keys_and_argv(lua_state, keys, argv, args)

lua_state.eval('unpack = table.unpack')

lua_state.function 'redis.call' do |cmd, *args|
lua_bound_redis_call(cmd, *args)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mock_redis_lua_extension/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module MockRedisLuaExtension
VERSION = "0.3.0".freeze
VERSION = "0.3.1.pre.0".freeze
end
13 changes: 13 additions & 0 deletions spec/mock_redis_lua_extension_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@
result = redis.eval('return KEYS[1]', keys: [:stuff])
expect(result).to eq('stuff')
end

it 'supports the unpack function, as equivalent to table.unpack' do
unpack_lua_script = '
local t = {1, 2, 3, 4, 5}
return {unpack(t, 2, 4)}
'.strip
table_unpack_lua_script = '
local t = {1, 2, 3, 4, 5}
return {table.unpack(t, 2, 4)}
'.strip
expect(redis.eval(unpack_lua_script)).to eq([2, 3, 4])
expect(redis.eval(table_unpack_lua_script)).to eq([2, 3, 4])
end
end

context 'marshalling lua args to redis.call' do
Expand Down
Loading