@fedify/redis 0.3.0 → 0.4.0-dev.18
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 +9 -2
- package/esm/src/kv.js +1 -1
- package/esm/src/mq.js +22 -1
- package/package.json +6 -6
- package/script/src/kv.js +1 -1
- package/script/src/mq.js +22 -1
- package/types/src/mq.d.ts +1 -0
- package/types/src/mq.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -28,8 +28,8 @@ const federation = createFederation({
|
|
|
28
28
|
[JSR badge]: https://jsr.io/badges/@fedify/redis
|
|
29
29
|
[npm]: https://www.npmjs.com/package/@fedify/redis
|
|
30
30
|
[npm badge]: https://img.shields.io/npm/v/@fedify/redis?logo=npm
|
|
31
|
-
[GitHub Actions]: https://github.com/
|
|
32
|
-
[GitHub Actions badge]: https://github.com/
|
|
31
|
+
[GitHub Actions]: https://github.com/fedify-dev/redis/actions/workflows/main.yaml
|
|
32
|
+
[GitHub Actions badge]: https://github.com/fedify-dev/redis/actions/workflows/main.yaml/badge.svg
|
|
33
33
|
[Fedify]: https://fedify.dev/
|
|
34
34
|
[`KvStore`]: https://jsr.io/@fedify/fedify/doc/federation/~/KvStore
|
|
35
35
|
[`MessageQueue`]: https://jsr.io/@fedify/fedify/doc/federation/~/MessageQueue
|
|
@@ -62,6 +62,13 @@ bun add @fedify/redis
|
|
|
62
62
|
Changelog
|
|
63
63
|
---------
|
|
64
64
|
|
|
65
|
+
### Version 0.4.0
|
|
66
|
+
|
|
67
|
+
To be released.
|
|
68
|
+
|
|
69
|
+
- Added `RedisMessageQueue.enqueueMany()` method for efficiently enqueueing
|
|
70
|
+
multiple messages in a single transaction.
|
|
71
|
+
|
|
65
72
|
### Version 0.3.0
|
|
66
73
|
|
|
67
74
|
Released on October 4, 2024.
|
package/esm/src/kv.js
CHANGED
|
@@ -73,5 +73,5 @@ _RedisKvStore_redis = new WeakMap(), _RedisKvStore_keyPrefix = new WeakMap(), _R
|
|
|
73
73
|
return `${__classPrivateFieldGet(this, _RedisKvStore_keyPrefix, "f")}${suffix}`;
|
|
74
74
|
}
|
|
75
75
|
const suffixBytes = __classPrivateFieldGet(this, _RedisKvStore_textEncoder, "f").encode(suffix);
|
|
76
|
-
return Buffer.concat([__classPrivateFieldGet(this, _RedisKvStore_keyPrefix, "f"), suffixBytes]);
|
|
76
|
+
return Buffer.concat([new Uint8Array(__classPrivateFieldGet(this, _RedisKvStore_keyPrefix, "f")), suffixBytes]);
|
|
77
77
|
};
|
package/esm/src/mq.js
CHANGED
|
@@ -68,6 +68,27 @@ export class RedisMessageQueue {
|
|
|
68
68
|
if (ts < 1)
|
|
69
69
|
__classPrivateFieldGet(this, _RedisMessageQueue_redis, "f").publish(__classPrivateFieldGet(this, _RedisMessageQueue_channelKey, "f"), "");
|
|
70
70
|
}
|
|
71
|
+
async enqueueMany(messages, options) {
|
|
72
|
+
if (messages.length === 0)
|
|
73
|
+
return;
|
|
74
|
+
const ts = options?.delay == null
|
|
75
|
+
? 0
|
|
76
|
+
: dntShim.Temporal.Now.instant().add(options.delay).epochMilliseconds;
|
|
77
|
+
// Use multi to batch multiple ZADD commands:
|
|
78
|
+
const multi = __classPrivateFieldGet(this, _RedisMessageQueue_redis, "f").multi();
|
|
79
|
+
for (const message of messages) {
|
|
80
|
+
const encodedMessage = __classPrivateFieldGet(this, _RedisMessageQueue_codec, "f").encode([
|
|
81
|
+
crypto.randomUUID(),
|
|
82
|
+
message,
|
|
83
|
+
]);
|
|
84
|
+
multi.zadd(__classPrivateFieldGet(this, _RedisMessageQueue_queueKey, "f"), ts, encodedMessage);
|
|
85
|
+
}
|
|
86
|
+
// Execute all commands in a single transaction:
|
|
87
|
+
await multi.exec();
|
|
88
|
+
// Notify only if there's no delay:
|
|
89
|
+
if (ts < 1)
|
|
90
|
+
__classPrivateFieldGet(this, _RedisMessageQueue_redis, "f").publish(__classPrivateFieldGet(this, _RedisMessageQueue_channelKey, "f"), "");
|
|
91
|
+
}
|
|
71
92
|
async listen(handler, options = {}) {
|
|
72
93
|
if (__classPrivateFieldGet(this, _RedisMessageQueue_loopHandle, "f") != null) {
|
|
73
94
|
throw new Error("Already listening");
|
|
@@ -80,7 +101,7 @@ export class RedisMessageQueue {
|
|
|
80
101
|
message = await __classPrivateFieldGet(this, _RedisMessageQueue_instances, "m", _RedisMessageQueue_poll).call(this);
|
|
81
102
|
}
|
|
82
103
|
catch (error) {
|
|
83
|
-
logger.error("Error polling for messages: {error}", error);
|
|
104
|
+
logger.error("Error polling for messages: {error}", { error });
|
|
84
105
|
return;
|
|
85
106
|
}
|
|
86
107
|
if (message === undefined)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/redis",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0-dev.18+5b5b5a7b",
|
|
4
4
|
"description": "Redis drivers for Fedify",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fedify",
|
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
"email": "hong@minhee.org",
|
|
12
12
|
"url": "https://hongminhee.org/"
|
|
13
13
|
},
|
|
14
|
-
"homepage": "https://github.com/
|
|
14
|
+
"homepage": "https://github.com/fedify-dev/redis",
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
17
|
-
"url": "git+https://github.com/
|
|
17
|
+
"url": "git+https://github.com/fedify-dev/redis.git"
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"bugs": {
|
|
21
|
-
"url": "https://github.com/
|
|
21
|
+
"url": "https://github.com/fedify-dev/redis/issues"
|
|
22
22
|
},
|
|
23
23
|
"main": "./script/mod.js",
|
|
24
24
|
"module": "./esm/mod.js",
|
|
@@ -59,8 +59,8 @@
|
|
|
59
59
|
"https://github.com/sponsors/dahlia"
|
|
60
60
|
],
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@fedify/fedify": "
|
|
63
|
-
"@logtape/logtape": "^0.
|
|
62
|
+
"@fedify/fedify": "1.5.0-dev.732",
|
|
63
|
+
"@logtape/logtape": "^0.9.0",
|
|
64
64
|
"ioredis": "^5.4.1",
|
|
65
65
|
"@deno/shim-deno": "~0.18.0",
|
|
66
66
|
"@js-temporal/polyfill": "^0.4.4"
|
package/script/src/kv.js
CHANGED
|
@@ -77,5 +77,5 @@ _RedisKvStore_redis = new WeakMap(), _RedisKvStore_keyPrefix = new WeakMap(), _R
|
|
|
77
77
|
return `${__classPrivateFieldGet(this, _RedisKvStore_keyPrefix, "f")}${suffix}`;
|
|
78
78
|
}
|
|
79
79
|
const suffixBytes = __classPrivateFieldGet(this, _RedisKvStore_textEncoder, "f").encode(suffix);
|
|
80
|
-
return node_buffer_1.Buffer.concat([__classPrivateFieldGet(this, _RedisKvStore_keyPrefix, "f"), suffixBytes]);
|
|
80
|
+
return node_buffer_1.Buffer.concat([new Uint8Array(__classPrivateFieldGet(this, _RedisKvStore_keyPrefix, "f")), suffixBytes]);
|
|
81
81
|
};
|
package/script/src/mq.js
CHANGED
|
@@ -94,6 +94,27 @@ class RedisMessageQueue {
|
|
|
94
94
|
if (ts < 1)
|
|
95
95
|
__classPrivateFieldGet(this, _RedisMessageQueue_redis, "f").publish(__classPrivateFieldGet(this, _RedisMessageQueue_channelKey, "f"), "");
|
|
96
96
|
}
|
|
97
|
+
async enqueueMany(messages, options) {
|
|
98
|
+
if (messages.length === 0)
|
|
99
|
+
return;
|
|
100
|
+
const ts = options?.delay == null
|
|
101
|
+
? 0
|
|
102
|
+
: dntShim.Temporal.Now.instant().add(options.delay).epochMilliseconds;
|
|
103
|
+
// Use multi to batch multiple ZADD commands:
|
|
104
|
+
const multi = __classPrivateFieldGet(this, _RedisMessageQueue_redis, "f").multi();
|
|
105
|
+
for (const message of messages) {
|
|
106
|
+
const encodedMessage = __classPrivateFieldGet(this, _RedisMessageQueue_codec, "f").encode([
|
|
107
|
+
crypto.randomUUID(),
|
|
108
|
+
message,
|
|
109
|
+
]);
|
|
110
|
+
multi.zadd(__classPrivateFieldGet(this, _RedisMessageQueue_queueKey, "f"), ts, encodedMessage);
|
|
111
|
+
}
|
|
112
|
+
// Execute all commands in a single transaction:
|
|
113
|
+
await multi.exec();
|
|
114
|
+
// Notify only if there's no delay:
|
|
115
|
+
if (ts < 1)
|
|
116
|
+
__classPrivateFieldGet(this, _RedisMessageQueue_redis, "f").publish(__classPrivateFieldGet(this, _RedisMessageQueue_channelKey, "f"), "");
|
|
117
|
+
}
|
|
97
118
|
async listen(handler, options = {}) {
|
|
98
119
|
if (__classPrivateFieldGet(this, _RedisMessageQueue_loopHandle, "f") != null) {
|
|
99
120
|
throw new Error("Already listening");
|
|
@@ -106,7 +127,7 @@ class RedisMessageQueue {
|
|
|
106
127
|
message = await __classPrivateFieldGet(this, _RedisMessageQueue_instances, "m", _RedisMessageQueue_poll).call(this);
|
|
107
128
|
}
|
|
108
129
|
catch (error) {
|
|
109
|
-
logger.error("Error polling for messages: {error}", error);
|
|
130
|
+
logger.error("Error polling for messages: {error}", { error });
|
|
110
131
|
return;
|
|
111
132
|
}
|
|
112
133
|
if (message === undefined)
|
package/types/src/mq.d.ts
CHANGED
|
@@ -66,6 +66,7 @@ export declare class RedisMessageQueue implements MessageQueue, Disposable {
|
|
|
66
66
|
*/
|
|
67
67
|
constructor(redis: () => Redis, options?: RedisMessageQueueOptions);
|
|
68
68
|
enqueue(message: any, options?: MessageQueueEnqueueOptions): Promise<void>;
|
|
69
|
+
enqueueMany(messages: any[], options?: MessageQueueEnqueueOptions): Promise<void>;
|
|
69
70
|
listen(handler: (message: any) => void | Promise<void>, options?: MessageQueueListenOptions): Promise<void>;
|
|
70
71
|
[Symbol.dispose](): void;
|
|
71
72
|
}
|
package/types/src/mq.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mq.d.ts","sourceRoot":"","sources":["../../src/src/mq.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,kBAA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