@crvouga/mockingbird-service-redis 2.12.0 → 2.13.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
@@ -26,10 +26,9 @@ import { Redis } from "ioredis"
26
26
  import { createRedis, manualClock } from "@crvouga/mockingbird-service-redis"
27
27
  import { serve } from "@crvouga/mockingbird-service-redis/server"
28
28
 
29
- // Test setup: an emulator on a manual clock, listening on a free port. `as never` is needed
30
- // because the two entry points bundle separate declarations of the `Redis` type.
29
+ // Test setup: an emulator on a manual clock, listening on a free port.
31
30
  const emulator = createRedis({ clock: manualClock(1_700_000_000_000) })
32
- const server = await serve(emulator as never, { port: 0 })
31
+ const server = await serve(emulator, { port: 0 })
33
32
 
34
33
  // Application code: the ioredis client it already uses, connected to the emulator.
35
34
  const redis = new Redis({ host: server.host, port: server.port })
@@ -51,6 +50,34 @@ are the test controls.
51
50
  `ioredis` connects to the TCP server unchanged. Cluster `MOVED` / `ASK` is not implemented:
52
51
  `CLUSTER` and `READONLY` answer that cluster support is disabled.
53
52
 
53
+ ### Without a listener (browser, worker, edge)
54
+
55
+ `createRespServer(redis, options?)` from `@crvouga/mockingbird-service-redis/transport` is the same
56
+ RESP server with no TCP listener and no `node:` import, so it bundles for a browser or worker.
57
+ `server.accept(stream)` serves one client connection given as `{ readable, writable }` web byte
58
+ streams or a Node `Duplex`, and resolves when that connection closes; the session's blocking
59
+ waiters, `MULTI` state, subscriptions and `CLIENT` registration are then released. `serve()` is this
60
+ server behind `net.createServer`. Options are `admit` and `controlPrivileged` as for `serve()`, plus
61
+ `closeEngine` (default `true`) for `server.close()`. The connection shape is the same as
62
+ `createWireServer` from `@crvouga/mockingbird-service-postgres/transport`.
63
+
64
+ ```ts
65
+ import { createRedis } from "@crvouga/mockingbird-service-redis"
66
+ import { createRespServer } from "@crvouga/mockingbird-service-redis/transport"
67
+
68
+ const server = createRespServer(createRedis())
69
+ const toServer = new TransformStream<Uint8Array, Uint8Array>()
70
+ const toClient = new TransformStream<Uint8Array, Uint8Array>()
71
+ void server.accept({ readable: toServer.readable, writable: toClient.writable })
72
+ // Hand the other ends (toServer.writable, toClient.readable) to the client as a socket, e.g.
73
+ // through ioredis's `Connector` option.
74
+ ```
75
+
76
+ The server writes replies in the order it produces them. Your client-side socket must deliver
77
+ chunks in order too: `ioredis` and BullMQ assume bytes written in one tick arrive before a timer of
78
+ the next, so schedule delivery on a microtask or a `MessageChannel`, not `setTimeout(0)` (clamped to
79
+ 4 ms in a browser).
80
+
54
81
  `mockingbird-redis serve --config mockingbird.json` supervises mixed HTTP/Postgres/Redis fleets.
55
82
  See [fleet configuration and controls](../../../docs/FLEETS.md) for ephemeral discovery, namespace
56
83
  endpoints, readiness, shutdown and coordinated state controls.
@@ -65,6 +92,9 @@ endpoints, readiness, shutdown and coordinated state controls.
65
92
  - `RedisReplyError` is a Redis error reply raised by `call`.
66
93
  - `manualClock(start)` moves only when `advance` is called. `wallClock` follows `Date.now()`.
67
94
  - `encodeReply(reply, protocol)` writes a RESP2 or RESP3 frame.
95
+ - `/server`: `serve(redis, options?)` listens over TCP; `serveTarget` boots it from `serve --config`.
96
+ - `/transport`: `createRespServer(redis, options?)` returns `{ accept(stream), connections, close() }`
97
+ with no listener (see above).
68
98
 
69
99
  ## Deliberately not modelled
70
100
 
package/SUPPORT.md CHANGED
@@ -89,6 +89,16 @@ run). Tests: `test/redis.commands.test.ts`.
89
89
  | `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
90
  | `COMMAND GETKEYSANDFLAGS`, `COMMAND HELP` | **Unsupported**, explicit `ERR COMMAND <sub> is not supported by the Mockingbird Redis emulator`. |
91
91
 
92
+ ## Transports (#698)
93
+
94
+ The RESP server runs over TCP (`serve` from `/server`, Node and Bun) or over any injected
95
+ connection (`createRespServer` from `/transport`, no `node:` import: browser, worker, edge). Both
96
+ paths run the same session code, so blocking commands, `MULTI`, pub/sub and `CLIENT` behave the
97
+ same; a closed stream releases the session as a closed socket does. `test/redis.transport.test.ts`
98
+ drives it with unmodified ioredis over in-memory web streams and over a Node `Duplex`. Not a
99
+ vendor behaviour, so there is no oracle comparison; the in-process transport is a Mockingbird
100
+ feature.
101
+
92
102
  ## Fleet controls
93
103
 
94
104
  The fleet adapter supports dynamic namespace listeners, finite numeric seeds, boot/reset clocks,
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-22CTWFCU.js.map