@crvouga/mockingbird-service-redis 2.14.0 → 2.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -42,6 +42,10 @@ await redis.quit()
42
42
  await server.close()
43
43
  ```
44
44
 
45
+ Keyspace notifications work as in Redis: `CONFIG SET notify-keyspace-events Ex`, subscribe to
46
+ `__keyevent@0__:expired`, and `emulator.advance(ms)` publishes `expired` for every key it expires
47
+ before it returns (see [SUPPORT.md](SUPPORT.md#keyspace-notifications) for the events published).
48
+
45
49
  Two `createRedis()` instances never share keys. `SELECT` isolates logical databases 0–15 inside
46
50
  one instance. `emulator.advance(ms)` moves an injected clock. `emulator.inspect()`,
47
51
  `emulator.fault()`, `emulator.pauseConsumers()`, `emulator.reset()`, and `emulator.waiterCount()`
@@ -111,4 +115,9 @@ endpoints, readiness, shutdown and coordinated state controls.
111
115
  and differentially checked against redis-server 8.4.0; see [SUPPORT.md](SUPPORT.md). BullMQ 5.76.2
112
116
  queue/worker flows are covered by the public-client suite.
113
117
  - `XADD` / `XTRIM` `MAXLEN ~` trims exactly.
118
+ - Best guess, not oracle-verified: `PFCOUNT` is exact (a HyperLogLog is stored as an exact member
119
+ set behind Redis's `HYLL` magic), where Redis estimates with a 0.81% standard error.
120
+ - Keyspace `keymiss` (`m`), module (`d`) and hash-field expiry events are accepted but never
121
+ published. `FUNCTION DUMP`/`RESTORE` return an explicit unsupported error, and function libraries
122
+ are not part of snapshots.
114
123
  - Set members are returned in byte order so results stay deterministic.
package/SUPPORT.md CHANGED
@@ -6,17 +6,19 @@ spot checks. The server reports `redis_version` 7.2.4 and `redis_mode:standalone
6
6
  | area | commands | notes |
7
7
  | --- | --- | --- |
8
8
  | connection | `AUTH`, `HELLO`, `PING`, `QUIT`, `RESET`, `SELECT`, `CLIENT`, `INFO`, `ECHO` | RESP2 and RESP3. `HELLO 3` switches before its map reply. |
9
- | strings | `GET`, `SET`, `MGET`, `MSET`, `INCR`, `DECR`, `APPEND`, `GETSET`, `GETDEL`, `GETEX` | `NX` `XX` `EX` `PX` `EXAT` `PXAT` `KEEPTTL` `GET`. |
9
+ | strings | `GET`, `SET`, `MGET`, `MSET`, `INCR`, `DECR`, `APPEND`, `GETSET`, `GETDEL`, `GETEX`, `SETBIT`, `GETBIT`, `BITCOUNT` | `NX` `XX` `EX` `PX` `EXAT` `PXAT` `KEEPTTL` `GET`. `BITCOUNT` takes `BYTE`/`BIT` ranges. |
10
+ | HyperLogLog | `PFADD`, `PFCOUNT`, `PFMERGE` | Exact counts: best guess, see #753 below. |
10
11
  | expiration | `EXPIRE`, `PEXPIRE`, `EXPIREAT`, `PEXPIREAT`, `TTL`, `PTTL`, `PERSIST` | Injected clock. Negative `EXPIRE` deletes an existing key. |
11
- | keys | `DEL`, `EXISTS`, `TYPE`, `SCAN`, `KEYS`, `RENAME`, `FLUSHDB`, `FLUSHALL` | `SCAN` cursor is a bulk string. |
12
+ | keys | `DEL`, `EXISTS`, `TOUCH`, `TYPE`, `SCAN`, `KEYS`, `RENAME`, `FLUSHDB`, `FLUSHALL` | `SCAN` cursor is a bulk string. |
12
13
  | hashes | `HSET`, `HGET`, `HMGET`, `HGETALL`, `HDEL`, `HINCRBY` | |
13
- | lists | `LPUSH`, `RPUSH`, `LPOP`, `RPOP`, `LRANGE`, `LPOS`, `LMOVE`, `BLPOP`, `BRPOP` | Blocking waits release the command queue; LPOS supports RANK, COUNT and MAXLEN. |
14
- | sets | `SADD`, `SREM`, `SMEMBERS`, `SISMEMBER`, `SPOP` | Members are ordered bytewise. |
15
- | sorted sets | `ZADD`, `ZRANGE`, `ZPOPMIN`, `BZPOPMIN`, `ZINCRBY` | Integer scores encode without a trailing `.0`. |
16
- | streams | `XADD`, `XREAD`, `XGROUP`, `XREADGROUP`, `XACK`, `XPENDING`, `XCLAIM`, `XAUTOCLAIM` | Consumer-group pending entries and claim. |
14
+ | lists | `LPUSH`, `RPUSH`, `LPUSHX`, `RPUSHX`, `LPOP`, `RPOP`, `LRANGE`, `LPOS`, `LMOVE`, `BLPOP`, `BRPOP` | Blocking waits release the command queue; LPOS supports RANK, COUNT and MAXLEN. |
15
+ | sets | `SADD`, `SREM`, `SMEMBERS`, `SISMEMBER`, `SPOP`, `SINTER`/`SUNION`/`SDIFF` and their `STORE` forms, `SINTERCARD` | Members are ordered bytewise. |
16
+ | sorted sets | `ZADD`, `ZRANGE` (`BYSCORE`, `BYLEX`, `REV`, `LIMIT`), `ZRANGESTORE`, `ZRANGEBYLEX`, `ZREVRANGEBYLEX`, `ZLEXCOUNT`, `ZREMRANGEBYLEX`, `ZPOPMIN`, `BZPOPMIN`, `ZINCRBY`, `ZRANK ... WITHSCORE`, `ZUNION`/`ZINTER`/`ZDIFF` and their `STORE` forms, `ZINTERCARD`, `ZRANDMEMBER` | Scores print as Redis 7 does (`1e+20`, `1.5e-7`). RESP3 scores are doubles and `WITHSCORES` replies are `[member, score]` pairs. |
17
+ | streams | `XADD`, `XRANGE`, `XREVRANGE`, `XREAD`, `XGROUP`, `XREADGROUP`, `XACK`, `XPENDING`, `XCLAIM`, `XAUTOCLAIM` | Consumer-group pending entries and claim. `XRANGE`/`XREVRANGE` take `(` exclusive and incomplete (`ms`) IDs. |
17
18
  | transactions | `MULTI`, `EXEC`, `DISCARD`, `WATCH`, `UNWATCH` | A watched key change makes `EXEC` a null array. |
18
- | pub/sub | `SUBSCRIBE`, `UNSUBSCRIBE`, `PSUBSCRIBE`, `PUBLISH`, `PUBSUB` | |
19
- | scripts | `EVAL`, `EVALSHA`, `SCRIPT LOAD`, `SCRIPT EXISTS`, `SCRIPT FLUSH` | Lua 5.1 with Redis's libraries (see "Lua scripting" below). |
19
+ | pub/sub | `SUBSCRIBE`, `UNSUBSCRIBE`, `PSUBSCRIBE`, `PUBLISH`, `PUBSUB`, `SSUBSCRIBE`, `SUNSUBSCRIBE`, `SPUBLISH` | Sharded channels on one node. Keyspace notifications (`notify-keyspace-events`), see below. |
20
+ | scripts | `EVAL`, `EVALSHA`, `EVAL_RO`, `EVALSHA_RO`, `SCRIPT LOAD`, `SCRIPT EXISTS`, `SCRIPT FLUSH`, `FUNCTION LOAD`/`LIST`/`DELETE`/`FLUSH`/`STATS`, `FCALL`, `FCALL_RO` | Lua 5.1 with Redis's libraries (see "Lua scripting" below). |
21
+ | replication | `WAIT` | No replicas: answers `0` at once. |
20
22
  | cluster | `CLUSTER`, `READONLY`, `ASKING` | Single node: cluster support disabled. |
21
23
 
22
24
  BullMQ 5.76.2 is exercised through unmodified Queue, Worker, QueueEvents and FlowProducer clients:
@@ -89,6 +91,64 @@ run). Tests: `test/redis.commands.test.ts`.
89
91
  | `COMMAND`, `COMMAND COUNT`, `LIST` (incl. `FILTERBY`), `INFO`, `DOCS`, `GETKEYS` | Metadata for the commands the emulator implements (captured from redis-server 8.4.0 by `scripts/command-table.ts`). `COMMAND COUNT` is the number of those commands, not Redis's `272`. `GETKEYS` handles fixed key specs plus `EVAL`, `ZUNIONSTORE`-style `numkeys`, `LMPOP` and `XREAD`. Sub-command entries and key specifications inside `INFO` are empty arrays. |
90
92
  | `COMMAND GETKEYSANDFLAGS`, `COMMAND HELP` | **Unsupported**, explicit `ERR COMMAND <sub> is not supported by the Mockingbird Redis emulator`. |
91
93
 
94
+ ## Issue #753: XREVRANGE, RESP3 scores, keyspace notifications, missing commands
95
+
96
+ Unless marked **best guess, not oracle-verified**, every behavior below was compared byte for byte
97
+ against redis-server 7.4.12 (the `redis:7.4` Docker image), and the `COMMAND INFO` rows of the new
98
+ commands were captured from redis-server 8.4.0 (`scripts/command-table.ts`). Tests:
99
+ `test/redis.issue-753.test.ts`; `bun run parity` replays the deterministic commands against
100
+ `REDIS_URL` (passes against both 7.4.12 and 8.4.0).
101
+
102
+ | behavior | evidence |
103
+ | --- | --- |
104
+ | `XREVRANGE key end start [COUNT n]` returns newest first; `XRANGE`/`XREVRANGE` accept `(` exclusive and incomplete IDs, reject invalid IDs (`ERR Invalid stream ID ...`, `ERR invalid start/end ID for the interval`), and `COUNT 0` (or negative) is a null array | oracle |
105
+ | After `HELLO 3`: `ZRANGE`/`ZREVRANGE`/`ZRANGEBYSCORE`/`ZREVRANGEBYSCORE`/`ZUNION`/`ZINTER`/`ZDIFF`/`ZRANDMEMBER ... WITHSCORES` and `ZPOPMIN`/`ZPOPMAX` with a count reply `[member, double]` pairs; `ZPOPMIN`/`ZPOPMAX` without a count, `BZPOPMIN`/`BZPOPMAX` stay flat with a double score; `ZSCORE`, `ZMSCORE`, `ZINCRBY`, `ZADD INCR`, `ZRANK ... WITHSCORE` reply doubles. RESP2 and Lua scripts keep flat bulk-string replies | oracle |
106
+ | `HGETALL` and `CONFIG GET` reply RESP3 maps after `HELLO 3` | oracle |
107
+ | Scores print as Redis's `d2string` (integers within ±2^62, otherwise shortest digits laid out by `fpconv_dtoa`: `1e+20`, `1.5e-7`, `0.00001`) | oracle; Redis's grisu digits can be one digit longer than the shortest round trip (`1e23` prints `99999999999999990000000` there, `1e+23` here) |
108
+ | `TOUCH`, `LPUSHX`, `RPUSHX`, `SUNIONSTORE`, `SINTERSTORE`, `SDIFFSTORE`, `SINTERCARD`, `ZINTERSTORE`, `ZDIFFSTORE`, `ZUNION`, `ZINTER`, `ZDIFF`, `ZINTERCARD`, `ZRANGESTORE`, `ZRANGEBYLEX`, `ZREVRANGEBYLEX`, `ZLEXCOUNT`, `ZREMRANGEBYLEX`, `ZRANGE ... BYLEX`, `ZRANK ... WITHSCORE`, `SETBIT`, `GETBIT`, `BITCOUNT`, `WAIT` (0 at once, no replicas), `EVAL_RO`/`EVALSHA_RO` (write commands raise `Write commands are not allowed from read-only scripts.`), `SPUBLISH`/`SSUBSCRIBE`/`SUNSUBSCRIBE`, `PUBSUB SHARDCHANNELS`/`SHARDNUMSUB`, and their error replies | oracle |
109
+ | `ZRANDMEMBER` member choice | random in Redis; the emulator draws from its seeded generator (`createRedis({ seed })`), so the choice differs from Redis but repeats run to run |
110
+ | `PFADD`, `PFCOUNT`, `PFMERGE`: replies (`1`/`0`, `OK`), `TYPE` string, the `WRONGTYPE Key is not a valid HyperLogLog string value.` error and keyspace events | oracle |
111
+ | `PFCOUNT` is exact, and `GET`/`STRLEN` of an HLL key show this emulator's encoding (`HYLL` magic, then the members), not Redis's registers | **best guess, not oracle-verified**: Redis's estimate has a 0.81% standard error, so the exact count is what an approximate count converges to for small sets |
112
+ | `FUNCTION LOAD [REPLACE]` (metadata, compile and registration errors, `Function ... already exists`, `No functions registered`), `FCALL`/`FCALL_RO` (`Function not found`, key-count errors, `no-writes` flag, `*_ro` refusal, `user_function:N` error positions), `FUNCTION LIST [WITHCODE] [LIBRARYNAME]` (RESP2 shape), `DELETE`, `FLUSH` | oracle |
113
+ | `FUNCTION LIST` order (load order; Redis's is hash order), `FUNCTION LIST` flags as an array (Redis sends a RESP3 set), `FUNCTION KILL` answering `NOTBUSY`, `FUNCTION STATS` | **best guess, not oracle-verified** |
114
+ | `FUNCTION DUMP`, `RESTORE`, `HELP` | **Unsupported**: explicit `ERR FUNCTION <sub> is not supported by the Mockingbird Redis emulator` (emulator limitation, not a Redis error). Libraries are not part of `snapshot()` / fleet archives and `reset()` drops them. |
115
+
116
+ ### Keyspace notifications
117
+
118
+ `CONFIG SET notify-keyspace-events <classes>` accepts Redis's class characters (`K E g $ l s h z x e
119
+ t m d n A`), rejects anything else with Redis's `Invalid event class character` error, and
120
+ `CONFIG GET` prints the flags normalised exactly as Redis does (`Ex` reads back `xE`, `KEA` reads
121
+ back `AKE`, and `n` is dropped from the text next to `A` though still active). `CONFIG SET` takes
122
+ several parameter/value pairs at once and rejects a duplicate. The setting starts empty (nothing
123
+ published) and `emulator.reset()` clears it. Events are published as Redis does,
124
+ on `__keyspace@<db>__:<key>` (message: the event) and `__keyevent@<db>__:<event>` (message: the
125
+ key), to `SUBSCRIBE` and `PSUBSCRIBE` alike, and from commands inside `MULTI`/`EXEC` and scripts.
126
+
127
+ Expiry (`x`): a key whose TTL passes publishes `expired` when the injected clock moves past it
128
+ (`emulator.advance(ms)` delivers the event synchronously, before `advance` returns), when a command
129
+ touches it, or, on the wall clock, within about 100 ms (a timer runs only while `x` events are
130
+ enabled, like Redis's active-expiry cycle). Eviction under `allkeys-lru` publishes `evicted` (`e`).
131
+
132
+ Events published, observed against redis-server 7.4.12 command by command (including which no-op
133
+ calls publish nothing, e.g. `SET NX` on an existing key, a `ZADD` that changes nothing, an empty
134
+ `SINTERSTORE`, an `XTRIM` that trims nothing): `set`, `expire`, `persist`, `del`, `incrby`,
135
+ `incrbyfloat`, `append`, `setrange`, `setbit`, `rename_from`/`rename_to`, `copy_to`, `new`;
136
+ `lpush`, `rpush`, `lpop`, `rpop`, `lset`, `linsert`, `lrem`, `ltrim` (including `LMOVE`,
137
+ `RPOPLPUSH`, `LMPOP` and served `BLPOP`/`BRPOP`/`BLMOVE`, push before pop); `sadd`, `srem`, `spop`,
138
+ `sinterstore`, `sunionstore`, `sdiffstore`; `hset`, `hdel`, `hincrby`, `hincrbyfloat`; `zadd`,
139
+ `zincr`, `zrem`, `zpopmin`, `zpopmax`, `zremrangebyscore`, `zremrangebyrank`, `zremrangebylex`,
140
+ `zunionstore`, `zinterstore`, `zdiffstore`, `zrangestore`; `xadd`, `xtrim`, `xdel`,
141
+ `xgroup-create`, `xgroup-setid`, `xgroup-destroy`, `xgroup-createconsumer`,
142
+ `xgroup-delconsumer`; `pfadd`; `expired`; `evicted`. A blocked client served by a write publishes
143
+ its pop after the write's own event, as Redis serves it after the command.
144
+
145
+ Not published (the class is accepted, nothing is sent): key-miss events (`m`, `keymiss`), module
146
+ events (`d`), hash-field expiry events (`hexpire`, `hpersist`, `hexpired`), `xgroup-createconsumer`
147
+ for a consumer `XREADGROUP` creates implicitly, `XCLAIM`/`XAUTOCLAIM`/`XACK` events, and events for
148
+ commands the emulator does not implement (`MOVE`, `SORT ... STORE`, `RESTORE`, ...). The `new`
149
+ event for a key is published before the command's own event; its position relative to `expired`
150
+ events of other keys is a best guess.
151
+
92
152
  ## Transports (#698)
93
153
 
94
154
  The RESP server runs over TCP (`serve` from `/server`, Node and Bun) or over any injected