Flatten array arguments in legacyMode multi commands #2064
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
#2071
In legacy mode multi commands, array arguments are not flattened. This is a bug.
For example, this command that adds two elements to a set:
sadd('a', ['b', 'c'])
when called in a multi will instead add the single element "['b', 'c']".
This bug is a blocker that surfaced while trying to upgrade from node-redis v3 to v4.
The root problem seems to be an inconsistency with the schema of queued multi vs single command arguments.
In a non-multi, the command that gets queued up in our sadd example would be:
["sAdd", "a", ["b", "c"]]
This is later flattened before getting serialized into a redis command.
However, multi commands queue up commands as the tuple: [commandName, args]. In this example:
["sAdd", ["a", ["b", "c"]]]
This is also flattened before getting serialized into a redis command, but only to one level, which is why this issue only surfaces for array arguments.
We fix this inconsistency in this diff by enqueing multi commands in the same format as their non-multi counterparts.
Thank you!
Checklist
npm test
pass with this change (including linting)?