@antelopejs/redis 1.1.2-next.84.g2449977 → 1.1.2-next.87.g2c81038

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
@@ -64,7 +64,7 @@ export default defineConfig({
64
64
  | `useMock` | Serves an in-memory [`ioredis-mock`](https://github.com/stipsan/ioredis-mock) client instead of connecting, and ignores every other key. For tests only. |
65
65
  | any other key | Passed to the client as [`ioredis` options](https://github.com/redis/ioredis#connect-to-redis), such as `host`, `port`, `password`, `db`, `tls` or `lazyConnect`. |
66
66
 
67
- The module creates the client when it starts, and quits it when it stops. With `lazyConnect: true`, the module waits for the connection before it serves the client.
67
+ The module creates the client when it starts, and quits it when it stops. With `lazyConnect: true`, the module waits for the connection before it serves the client. Every `error` event of that client, such as a refused connection or an `EPIPE` on shutdown, goes to the AntelopeJS logger as a warning on the `redis` channel.
68
68
 
69
69
  ## Quick start
70
70
 
@@ -82,7 +82,20 @@ await client.set("greeting", "hello", "EX", 60);
82
82
  const greeting = await client.get("greeting");
83
83
  ```
84
84
 
85
- `GetClient()` waits until the module has started and set its client. For distributed jobs, add `@antelopejs/interface-redis-scheduler` and read its [documentation](https://interfaces.antelopejs.com/docs/redis-scheduler/introduction).
85
+ `GetClient()` waits until the module has started and set its client. After the module stops, a new call waits again until the next start serves a new client, so a hot reload does not fail callers. A client you create with `client.duplicate()`, such as a pub/sub subscriber, has no `error` listener: add your own before you connect it, or ioredis prints its errors as unhandled error events.
86
+
87
+ ```typescript
88
+ import { Logging } from "@antelopejs/interface-core/logging";
89
+ import { GetClient } from "@antelopejs/interface-redis";
90
+
91
+ const Logger = new Logging.Channel("my-module");
92
+ const client = await GetClient();
93
+ const subscriber = client.duplicate({ lazyConnect: true });
94
+ subscriber.on("error", (error) => Logger.Warn(error));
95
+ await subscriber.connect();
96
+ ```
97
+
98
+ For distributed jobs, add `@antelopejs/interface-redis-scheduler` and read its [documentation](https://interfaces.antelopejs.com/docs/redis-scheduler/introduction).
86
99
 
87
100
  ## Documentation
88
101
 
package/dist/index.js CHANGED
@@ -41,7 +41,9 @@ exports.destroy = destroy;
41
41
  exports.start = start;
42
42
  exports.stop = stop;
43
43
  const ioredis_1 = __importDefault(require("ioredis"));
44
+ const logging_1 = require("@antelopejs/interface-core/logging");
44
45
  const interface_redis_1 = require("@antelopejs/interface-redis");
46
+ const Logger = new logging_1.Logging.Channel("redis");
45
47
  let redisConfig;
46
48
  function construct(config) {
47
49
  redisConfig = config;
@@ -50,6 +52,7 @@ function destroy() { }
50
52
  let startedClient;
51
53
  async function start() {
52
54
  const client = await createRedisClient(redisConfig);
55
+ client.on("error", (error) => Logger.Warn(error));
53
56
  if (redisConfig.useMock || redisConfig.lazyConnect) {
54
57
  try {
55
58
  await client.connect();
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,8BAEC;AAED,0BAAkC;AAIlC,sBAYC;AAED,oBAQC;AAvCD,sDAAmD;AACnD,iEAAuD;AAOvD,IAAI,WAAwB,CAAC;AAC7B,SAAgB,SAAS,CAAC,MAAmB;IAC3C,WAAW,GAAG,MAAM,CAAC;AACvB,CAAC;AAED,SAAgB,OAAO,KAAU,CAAC;AAElC,IAAI,aAAgC,CAAC;AAE9B,KAAK,UAAU,KAAK;IACzB,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,WAAW,CAAC,CAAC;IACpD,IAAI,WAAW,CAAC,OAAO,IAAI,WAAW,CAAC,WAAW,EAAE,CAAC;QACnD,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;QACzB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,UAAU,EAAE,CAAC;YACpB,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IACD,aAAa,GAAG,MAAM,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AG,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,OAAO,EAAE,GAAG,MAAM,CAAC;IAC/C,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,IAAI,iBAAK,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IACD,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtC,OAAO,IAAI,iBAAK,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,IAAI,iBAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACjC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const node_assert_1 = __importDefault(require("node:assert"));
7
+ const logging_1 = require("@antelopejs/interface-core/logging");
8
+ const listener_1 = __importDefault(require("@antelopejs/interface-core/logging/listener"));
9
+ const interface_redis_1 = require("@antelopejs/interface-redis");
10
+ const index_1 = require("../index");
11
+ const CLOSED_PORT_URL = "redis://127.0.0.1:26391";
12
+ const PENDING_WINDOW_MS = 200;
13
+ function redisWarnings(logs) {
14
+ return logs
15
+ .filter((log) => log.channel === "redis" && log.levelId === logging_1.Logging.Level.WARN)
16
+ .flatMap((log) => log.args);
17
+ }
18
+ function settlesWithin(promise, ms) {
19
+ return Promise.race([
20
+ promise.then(() => true, () => true),
21
+ new Promise((resolve) => setTimeout(() => resolve(false), ms)),
22
+ ]);
23
+ }
24
+ describe("Client errors", () => {
25
+ const logs = [];
26
+ const collect = (log) => {
27
+ logs.push(log);
28
+ };
29
+ beforeEach(() => {
30
+ logs.length = 0;
31
+ listener_1.default.register(collect);
32
+ });
33
+ afterEach(async () => {
34
+ listener_1.default.unregister(collect);
35
+ await (0, index_1.stop)();
36
+ (0, index_1.construct)({ useMock: true });
37
+ await (0, index_1.start)();
38
+ });
39
+ it("forwards an error emitted by the served client to the redis channel", async () => {
40
+ const client = await (0, interface_redis_1.GetClient)();
41
+ const error = new Error("write EPIPE");
42
+ client.emit("error", error);
43
+ node_assert_1.default.deepStrictEqual(redisWarnings(logs), [error]);
44
+ });
45
+ it("forwards a refused connection of a real ioredis client to the redis channel", async () => {
46
+ await (0, index_1.stop)();
47
+ (0, index_1.construct)({
48
+ url: CLOSED_PORT_URL,
49
+ lazyConnect: true,
50
+ maxRetriesPerRequest: 0,
51
+ });
52
+ await node_assert_1.default.rejects((0, index_1.start)());
53
+ const codes = redisWarnings(logs).map((error) => error instanceof Error && "code" in error ? error.code : undefined);
54
+ (0, node_assert_1.default)(codes.includes("ECONNREFUSED"));
55
+ });
56
+ it("keeps GetClient pending after stop until the next start serves a new client", async () => {
57
+ const stopped = await (0, interface_redis_1.GetClient)();
58
+ await (0, index_1.stop)();
59
+ const next = (0, interface_redis_1.GetClient)();
60
+ node_assert_1.default.strictEqual(await settlesWithin(next, PENDING_WINDOW_MS), false);
61
+ (0, index_1.construct)({ useMock: true });
62
+ await (0, index_1.start)();
63
+ const served = await next;
64
+ node_assert_1.default.notStrictEqual(served, stopped);
65
+ node_assert_1.default.strictEqual(await served.ping(), "PONG");
66
+ });
67
+ });
68
+ //# sourceMappingURL=client-errors.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-errors.test.js","sourceRoot":"","sources":["../../src/test/client-errors.test.ts"],"names":[],"mappings":";;;;;AAAA,8DAAiC;AAEjC,gEAA6D;AAC7D,2FAEqD;AACrD,iEAAwD;AAExD,oCAAkD;AAElD,MAAM,eAAe,GAAG,yBAAyB,CAAC;AAClD,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAE9B,SAAS,aAAa,CAAC,IAAW;IAChC,OAAO,IAAI;SACR,MAAM,CACL,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,KAAK,OAAO,IAAI,GA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,EAAE,OAAO,CAAC,CAAC;QACvC,qBAAM,CAAC,WAAW,CAAC,MAAM,MAAM,CAAC,IAAI,EAAE,EAAE,MAAM,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antelopejs/redis",
3
- "version": "1.1.2-next.84.g2449977",
3
+ "version": "1.1.2-next.87.g2c81038",
4
4
  "description": "Redis module for AntelopeJS, implementing the Redis and Redis Scheduler interfaces with ioredis",
5
5
  "keywords": [
6
6
  "antelopejs",