-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
multi modifies input parameter #503
Comments
Nice find! As a general rule I think we should aim to have all input variables be immutable. (as in: ioredis should not modify them in any way) |
Could you provide a test case for this? The following code: const Redis = require('ioredis')
const redis = new Redis()
const redisCmds = [
[
"set",
"key1",
"data1"
],
[
"zadd",
"key2",
1,
"data2"
],
[
"zadd",
"key3",
1,
"data3"
],
[
"zadd",
"key4",
1,
"data4"
]
]
const pipeline = redis.multi(redisCmds)
pipeline.exec(function () {})
console.log(redisCmds) Logs: [ [ 'set', 'key1', 'data1' ],
[ 'zadd', 'key2', 1, 'data2' ],
[ 'zadd', 'key3', 1, 'data3' ],
[ 'zadd', 'key4', 1, 'data4' ] ] |
Interesting. I ran your test code. The only difference was I supplied a password in the Redis constructor. I got:
The other difference in my production code is that Did you run this with 3.1.1? I'm also using node v6.11.1. Update: Reconfigured Redis to not use a password and re-ran test. Same results. |
I dug into the ioredis code. It appears that the issue is in
|
Resolved with v3.1.2. |
Using ioredis 3.1.1 / redis 4.0.
When using multi/exec, I build an array of commands and arguments to pass to the multi constructor:
(I two-step this to more easily unit test and stub out with sinon.)
When the call to multi() returns, redisCmds has been modified. Specifically, the first entry in each array of redisCmds (the "command") is removed.
Here's an example of what is passed into multi():
Here's what redisCmds looks like after the return from multi():
My code later examines the results from exec and tries to use the content of redisCmds to log metrics and details of which commands failed (if any). However, since the 'commands' have been removed from redisCmds, I'm unable to provide the correct logging information.
I'll have to work around this for now by cloning the array, but it does not seem appropriate for multi() to be modifying the caller's data.
The text was updated successfully, but these errors were encountered: