@fedify/redis 1.9.0-dev.1408 → 1.9.0-dev.1415

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
@@ -16,12 +16,27 @@ implementations for Redis:
16
16
  ~~~~ typescript
17
17
  import { createFederation } from "@fedify/fedify";
18
18
  import { RedisKvStore, RedisMessageQueue } from "@fedify/redis";
19
- import { Redis } from "ioredis";
19
+ import { Redis, Cluster } from "ioredis";
20
20
 
21
+ // Using a standalone Redis instance:
21
22
  const federation = createFederation({
22
23
  kv: new RedisKvStore(new Redis()),
23
24
  queue: new RedisMessageQueue(() => new Redis()),
24
25
  });
26
+
27
+ // Using a Redis Cluster:
28
+ const federation = createFederation({
29
+ kv: new RedisKvStore(new Cluster([
30
+ { host: "127.0.0.1", port: 7000 },
31
+ { host: "127.0.0.1", port: 7001 },
32
+ { host: "127.0.0.1", port: 7002 },
33
+ ])),
34
+ queue: new RedisMessageQueue(() => new Cluster([
35
+ { host: "127.0.0.1", port: 7000 },
36
+ { host: "127.0.0.1", port: 7001 },
37
+ { host: "127.0.0.1", port: 7002 },
38
+ ])),
39
+ });
25
40
  ~~~~
26
41
 
27
42
  [JSR]: https://jsr.io/@fedify/redis
package/dist/kv.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import { Codec } from "./codec.js";
3
3
  import { KvKey, KvStore, KvStoreSetOptions } from "@fedify/fedify";
4
- import { Redis, RedisKey } from "ioredis";
4
+ import { Cluster, Redis, RedisKey } from "ioredis";
5
5
 
6
6
  //#region src/kv.d.ts
7
7
  /**
@@ -26,22 +26,34 @@ interface RedisKvStoreOptions {
26
26
  * ```ts ignore
27
27
  * import { createFederation } from "@fedify/fedify";
28
28
  * import { RedisKvStore } from "@fedify/redis";
29
- * import { Redis } from "ioredis";
29
+ * import { Redis, Cluster } from "ioredis";
30
30
  *
31
+ * // Using a standalone Redis instance:
31
32
  * const federation = createFederation({
32
33
  * // ...
33
34
  * kv: new RedisKvStore(new Redis()),
34
35
  * });
36
+ *
37
+ * // Using a Redis Cluster:
38
+ * const cluster = new Cluster([
39
+ * { host: "127.0.0.1", port: 7000 },
40
+ * { host: "127.0.0.1", port: 7001 },
41
+ * { host: "127.0.0.1", port: 7002 },
42
+ * ]);
43
+ * const federation = createFederation({
44
+ * // ...
45
+ * kv: new RedisKvStore(cluster),
46
+ * });
35
47
  * ```
36
48
  */
37
49
  declare class RedisKvStore implements KvStore {
38
50
  #private;
39
51
  /**
40
52
  * Creates a new Redis key–value store.
41
- * @param redis The Redis client to use.
53
+ * @param redis The Redis client (standalone or cluster) to use.
42
54
  * @param options The options for the key–value store.
43
55
  */
44
- constructor(redis: Redis, options?: RedisKvStoreOptions);
56
+ constructor(redis: Redis | Cluster, options?: RedisKvStoreOptions);
45
57
  get<T = unknown>(key: KvKey): Promise<T | undefined>;
46
58
  set(key: KvKey, value: unknown, options?: KvStoreSetOptions | undefined): Promise<void>;
47
59
  delete(key: KvKey): Promise<void>;
package/dist/kv.js CHANGED
@@ -12,12 +12,24 @@ import { Buffer } from "node:buffer";
12
12
  * ```ts ignore
13
13
  * import { createFederation } from "@fedify/fedify";
14
14
  * import { RedisKvStore } from "@fedify/redis";
15
- * import { Redis } from "ioredis";
15
+ * import { Redis, Cluster } from "ioredis";
16
16
  *
17
+ * // Using a standalone Redis instance:
17
18
  * const federation = createFederation({
18
19
  * // ...
19
20
  * kv: new RedisKvStore(new Redis()),
20
21
  * });
22
+ *
23
+ * // Using a Redis Cluster:
24
+ * const cluster = new Cluster([
25
+ * { host: "127.0.0.1", port: 7000 },
26
+ * { host: "127.0.0.1", port: 7001 },
27
+ * { host: "127.0.0.1", port: 7002 },
28
+ * ]);
29
+ * const federation = createFederation({
30
+ * // ...
31
+ * kv: new RedisKvStore(cluster),
32
+ * });
21
33
  * ```
22
34
  */
23
35
  var RedisKvStore = class {
@@ -27,7 +39,7 @@ var RedisKvStore = class {
27
39
  #textEncoder = new TextEncoder();
28
40
  /**
29
41
  * Creates a new Redis key–value store.
30
- * @param redis The Redis client to use.
42
+ * @param redis The Redis client (standalone or cluster) to use.
31
43
  * @param options The options for the key–value store.
32
44
  */
33
45
  constructor(redis, options = {}) {
package/dist/mq.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import { Codec } from "./codec.js";
3
3
  import { MessageQueue, MessageQueueEnqueueOptions, MessageQueueListenOptions } from "@fedify/fedify";
4
- import { Redis, RedisKey } from "ioredis";
4
+ import { Cluster, Redis, RedisKey } from "ioredis";
5
5
 
6
6
  //#region src/mq.d.ts
7
7
  /**
@@ -51,12 +51,23 @@ interface RedisMessageQueueOptions {
51
51
  * ```ts ignore
52
52
  * import { createFederation } from "@fedify/fedify";
53
53
  * import { RedisMessageQueue } from "@fedify/redis";
54
- * import { Redis } from "ioredis";
54
+ * import { Redis, Cluster } from "ioredis";
55
55
  *
56
+ * // Using a standalone Redis instance:
56
57
  * const federation = createFederation({
57
58
  * // ...
58
59
  * queue: new RedisMessageQueue(() => new Redis()),
59
60
  * });
61
+ *
62
+ * // Using a Redis Cluster:
63
+ * const federation = createFederation({
64
+ * // ...
65
+ * queue: new RedisMessageQueue(() => new Cluster([
66
+ * { host: "127.0.0.1", port: 7000 },
67
+ * { host: "127.0.0.1", port: 7001 },
68
+ * { host: "127.0.0.1", port: 7002 },
69
+ * ])),
70
+ * });
60
71
  * ```
61
72
  */
62
73
  declare class RedisMessageQueue implements MessageQueue, Disposable {
@@ -66,7 +77,7 @@ declare class RedisMessageQueue implements MessageQueue, Disposable {
66
77
  * @param redis The Redis client factory.
67
78
  * @param options The options for the message queue.
68
79
  */
69
- constructor(redis: () => Redis, options?: RedisMessageQueueOptions);
80
+ constructor(redis: () => Redis | Cluster, options?: RedisMessageQueueOptions);
70
81
  enqueue(message: any, options?: MessageQueueEnqueueOptions): Promise<void>;
71
82
  enqueueMany(messages: any[], options?: MessageQueueEnqueueOptions): Promise<void>;
72
83
  listen(handler: (message: any) => void | Promise<void>, options?: MessageQueueListenOptions): Promise<void>;
package/dist/mq.js CHANGED
@@ -17,12 +17,23 @@ const logger = getLogger([
17
17
  * ```ts ignore
18
18
  * import { createFederation } from "@fedify/fedify";
19
19
  * import { RedisMessageQueue } from "@fedify/redis";
20
- * import { Redis } from "ioredis";
20
+ * import { Redis, Cluster } from "ioredis";
21
21
  *
22
+ * // Using a standalone Redis instance:
22
23
  * const federation = createFederation({
23
24
  * // ...
24
25
  * queue: new RedisMessageQueue(() => new Redis()),
25
26
  * });
27
+ *
28
+ * // Using a Redis Cluster:
29
+ * const federation = createFederation({
30
+ * // ...
31
+ * queue: new RedisMessageQueue(() => new Cluster([
32
+ * { host: "127.0.0.1", port: 7000 },
33
+ * { host: "127.0.0.1", port: 7001 },
34
+ * { host: "127.0.0.1", port: 7002 },
35
+ * ])),
36
+ * });
26
37
  * ```
27
38
  */
28
39
  var RedisMessageQueue = class {
@@ -104,9 +115,24 @@ var RedisMessageQueue = class {
104
115
  }
105
116
  };
106
117
  const promise = this.#subRedis.subscribe(this.#channelKey, () => {
107
- this.#subRedis.on("message", poll);
118
+ /**
119
+ * Cast to Redis for event methods. Both Redis and Cluster extend EventEmitter
120
+ * and get the same methods via applyMixin at runtime, but their TypeScript
121
+ * interfaces are incompatible:
122
+ * - Redis declares specific overloads: on(event: "message", cb: (channel, message) => void)
123
+ * - Cluster only has generic: on(event: string | symbol, listener: Function)
124
+ *
125
+ * This makes the union type Redis | Cluster incompatible for these method calls.
126
+ * The cast is safe because both classes use applyMixin(Class, EventEmitter) which
127
+ * copies all EventEmitter prototype methods, giving them identical pub/sub functionality.
128
+ *
129
+ * @see https://github.com/redis/ioredis/blob/main/lib/Redis.ts#L863 (has specific overloads)
130
+ * @see https://github.com/redis/ioredis/blob/main/lib/cluster/index.ts#L1110 (empty interface)
131
+ */
132
+ const subRedis = this.#subRedis;
133
+ subRedis.on("message", poll);
108
134
  signal?.addEventListener("abort", () => {
109
- this.#subRedis.off("message", poll);
135
+ subRedis.off("message", poll);
110
136
  });
111
137
  });
112
138
  signal?.addEventListener("abort", () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fedify/redis",
3
- "version": "1.9.0-dev.1408+7c78ce1a",
3
+ "version": "1.9.0-dev.1415+1d51c69c",
4
4
  "description": "Redis drivers for Fedify",
5
5
  "keywords": [
6
6
  "fedify",
@@ -62,7 +62,7 @@
62
62
  },
63
63
  "peerDependencies": {
64
64
  "ioredis": "^5.6.1",
65
- "@fedify/fedify": "1.9.0-dev.1408+7c78ce1a"
65
+ "@fedify/fedify": "1.9.0-dev.1415+1d51c69c"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@std/async": "npm:@jsr/std__async@^1.0.13",