@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 +21 -9
- package/dist/chunk-LHM64CLD.js +766 -0
- package/dist/chunk-LHM64CLD.js.map +7 -0
- package/dist/cli.js +133 -23
- package/dist/cli.js.map +3 -3
- package/dist/server.d.ts +210 -1
- package/dist/server.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-EKVFDNUN.js +0 -329
- package/dist/chunk-EKVFDNUN.js.map +0 -7
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
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
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. `
|
|
37
|
-
`
|
|
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`
|
|
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.
|