ioredis: nodejs.RangeError: Maximum call stack size exceeded when use hmset

when hmset get too much args(i passed 163368 args),it will report nodejs.RangeError: Maximum call stack size exceeded

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (3 by maintainers)

Most upvoted comments

Still encountering it to this day ✋

I ran into this too, and I think it’s mostly a documentation issue that ioredis really should address.

Essentially, the ioredis APIs for hmset, hmget, and possibly others are documented as though the arguments to the command must be passed as arguments one by one. I.e., if you want to set 100,000 hash keys, the docs suggest you’d call commander.hmset with 200,001 arguments (200,000 for the hash keys and their values, plus one for the redis key holding the hash). But, as noted in the OP, trying to call a method with so many arguments causes v8 to crash, because each argument gets allocated as a variable in the function’s stack frame.

The simplest workaround is actually to call commander.hmset("keyHoldingHash", my200_000ItemArray). This works because the Command class flattens it’s arguments — which is great, but that’s the part that’s totally undocumented and that it’s unclear whether callers can safely rely on. So, if that flattening is here to stay, it should be documented, probably with a note that it can be used with any command to work around this limit on the number of arguments allowed to a function call.