stipsan / ioredis-mock

Emulates ioredis by performing all operations in-memory.
MIT License
333 stars 125 forks source link

fix: xadd inconsistency with redis implementation #1343

Open ullumullu opened 7 months ago

ullumullu commented 7 months ago

This commit aligns id generation with the official "specification/docu":

Both quantities are 64-bit numbers. When an ID is auto-generated, the first part is the Unix time in milliseconds of the Redis instance generating the ID. The second part is just a sequence number and is used in order to distinguish IDs generated in the same millisecond.

Main motivation is that the current implementation was flawed when using capped streams by creating invalid ids (e.g. generating the same id twice) as well as re-using mocked tests and run them in an e2e fashion.

Tests were added to cover the enhanced functionality.

Links: https://redis.io/commands/xadd/

ullumullu commented 2 months ago

Hi @stipsan any comments on this PR would be appreciated. Thanks in advance.