@crvouga/mockingbird-service-redis 2.2.0 → 2.3.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
@@ -22,21 +22,33 @@ npm install -D @crvouga/mockingbird-service-redis
22
22
  ## Usage
23
23
 
24
24
  ```ts
25
+ import { Redis } from "ioredis"
25
26
  import { createRedis, manualClock } from "@crvouga/mockingbird-service-redis"
27
+ import { serve } from "@crvouga/mockingbird-service-redis/server"
26
28
 
27
- const clock = manualClock(1_700_000_000_000)
28
- const redis = createRedis({ clock })
29
- const client = redis.client()
30
- const set = await client.call("SET", "lock", "token", "PX", 1000)
31
- console.log(set)
32
- redis.advance(1000)
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.
31
+ const emulator = createRedis({ clock: manualClock(1_700_000_000_000) })
32
+ const server = await serve(emulator as never, { port: 0 })
33
+
34
+ // Application code: the ioredis client it already uses, connected to the emulator.
35
+ const redis = new Redis({ host: server.host, port: server.port })
36
+ console.log(await redis.set("lock", "token", "PX", 1000)) // OK
37
+
38
+ // Test control: expire the lock without sleeping.
39
+ emulator.advance(1000)
40
+ console.log(await redis.get("lock")) // null
41
+
42
+ await redis.quit()
43
+ await server.close()
33
44
  ```
34
45
 
35
46
  Two `createRedis()` instances never share keys. `SELECT` isolates logical databases 0–15 inside
36
- one instance. `redis.advance(ms)` moves an injected clock. `redis.inspect()`, `redis.fault()`,
37
- `redis.pauseConsumers()`, `redis.reset()`, and `redis.waiterCount()` are the test controls.
47
+ one instance. `emulator.advance(ms)` moves an injected clock. `emulator.inspect()`,
48
+ `emulator.fault()`, `emulator.pauseConsumers()`, `emulator.reset()`, and `emulator.waiterCount()`
49
+ are the test controls.
38
50
 
39
- `ioredis` can connect to the TCP server unchanged. Cluster `MOVED` / `ASK` is not implemented:
51
+ `ioredis` connects to the TCP server unchanged. Cluster `MOVED` / `ASK` is not implemented:
40
52
  `CLUSTER` and `READONLY` answer that cluster support is disabled.
41
53
 
42
54
  `mockingbird-redis serve --config mockingbird.json` supervises mixed HTTP/Postgres/Redis fleets.