@yongdall/mq-redis 0.1.0 → 0.1.1
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/index.mjs +1 -1
- package/package.json +1 -1
- package/redis-COKcrILq.mjs +40 -0
- package/redis-COKcrILq.mjs.map +1 -0
- package/redis-CSe28ot7.mjs +0 -31
- package/redis-CSe28ot7.mjs.map +0 -1
package/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region providers/mq-redis/index.mjs
|
|
2
|
-
var mq_redis_default = (url) => import("./redis-
|
|
2
|
+
var mq_redis_default = (url) => import("./redis-COKcrILq.mjs").then((v) => v.default(url));
|
|
3
3
|
|
|
4
4
|
//#endregion
|
|
5
5
|
export { mq_redis_default as default };
|
package/package.json
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import IORedis from "ioredis";
|
|
2
|
+
|
|
3
|
+
//#region providers/mq-redis/redis.mjs
|
|
4
|
+
/** @import { MessageQueue } from '@yongdall/connection' */
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {string} url
|
|
8
|
+
* @returns {Promise<MessageQueue>}
|
|
9
|
+
*/
|
|
10
|
+
async function redis_default(url) {
|
|
11
|
+
const uri = new URL(url);
|
|
12
|
+
const redis = new IORedis({
|
|
13
|
+
host: uri.hostname,
|
|
14
|
+
port: parseInt(uri.port) || 6379,
|
|
15
|
+
username: uri.username,
|
|
16
|
+
password: uri.password,
|
|
17
|
+
db: parseInt(uri.pathname.slice(1)) || 0
|
|
18
|
+
});
|
|
19
|
+
const prefix = uri.searchParams.get("prefix") || "";
|
|
20
|
+
return {
|
|
21
|
+
async publish(channel, message) {
|
|
22
|
+
await redis.publish(`${prefix}${channel}`, JSON.stringify(message));
|
|
23
|
+
},
|
|
24
|
+
async subscribe(channel, subscriber) {
|
|
25
|
+
const name = `${prefix}${channel}`;
|
|
26
|
+
redis.subscribe(name, (err, count) => {});
|
|
27
|
+
redis.on("message", (messageChannel, message) => {
|
|
28
|
+
if (messageChannel !== name) return;
|
|
29
|
+
try {
|
|
30
|
+
subscriber(JSON.parse(message));
|
|
31
|
+
} catch {}
|
|
32
|
+
});
|
|
33
|
+
return () => redis.unsubscribe(name);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { redis_default as default };
|
|
40
|
+
//# sourceMappingURL=redis-COKcrILq.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis-COKcrILq.mjs","names":[],"sources":["../../providers/mq-redis/redis.mjs"],"sourcesContent":["import IORedis from 'ioredis';\n/** @import { MessageQueue } from '@yongdall/connection' */\n\n/**\n * \n * @param {string} url \n * @returns {Promise<MessageQueue>}\n */\nexport default async function(url) {\n\tconst uri = new URL(url);\n\tconst redis = new IORedis({\n\t\thost: uri.hostname,\n\t\tport: parseInt(uri.port) || 6379,\n\t\tusername: uri.username,\n\t\tpassword: uri.password,\n\t\tdb: parseInt(uri.pathname.slice(1)) || 0,\n\t});\n\tconst prefix = uri.searchParams.get('prefix') || '';\n\n\treturn {\n\t\tasync publish(channel, message) {\n\t\t\tawait redis.publish(`${prefix}${channel}`, JSON.stringify(message));\n\t\t},\n\t\tasync subscribe(channel, subscriber) {\n\t\t\tconst name = `${prefix}${channel}`;\n\n\t\t\tredis.subscribe(name, (err, count) => {\n\t\t\t\t// if (err) {\n\t\t\t\t// \tconsole.error(\"Failed to subscribe:\", err);\n\t\t\t\t// } else {\n\t\t\t\t// \tconsole.log(`Subscribed to ${count} channels.`);\n\t\t\t\t// }\n\t\t\t});\n\n\t\t\tredis.on(\"message\", (messageChannel, message) => {\n\t\t\t\tif (messageChannel !== name) { return; }\n\t\t\t\ttry {\n\t\t\t\t\tsubscriber(JSON.parse(message));\n\t\t\t\t} catch {\n\n\t\t\t\t}\n\t\t\t});\n\t\t\treturn () => redis.unsubscribe(name);\n\t\t}\n\t};\n}\n"],"mappings":";;;;;;;;;AAQA,6BAA8B,KAAK;CAClC,MAAM,MAAM,IAAI,IAAI,IAAI;CACxB,MAAM,QAAQ,IAAI,QAAQ;EACzB,MAAM,IAAI;EACV,MAAM,SAAS,IAAI,KAAK,IAAI;EAC5B,UAAU,IAAI;EACd,UAAU,IAAI;EACd,IAAI,SAAS,IAAI,SAAS,MAAM,EAAE,CAAC,IAAI;EACvC,CAAC;CACF,MAAM,SAAS,IAAI,aAAa,IAAI,SAAS,IAAI;AAEjD,QAAO;EACN,MAAM,QAAQ,SAAS,SAAS;AAC/B,SAAM,MAAM,QAAQ,GAAG,SAAS,WAAW,KAAK,UAAU,QAAQ,CAAC;;EAEpE,MAAM,UAAU,SAAS,YAAY;GACpC,MAAM,OAAO,GAAG,SAAS;AAEzB,SAAM,UAAU,OAAO,KAAK,UAAU,GAMpC;AAEF,SAAM,GAAG,YAAY,gBAAgB,YAAY;AAChD,QAAI,mBAAmB,KAAQ;AAC/B,QAAI;AACH,gBAAW,KAAK,MAAM,QAAQ,CAAC;YACxB;KAGP;AACF,gBAAa,MAAM,YAAY,KAAK;;EAErC"}
|
package/redis-CSe28ot7.mjs
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import IORedis from "ioredis";
|
|
2
|
-
|
|
3
|
-
//#region providers/mq-redis/redis.mjs
|
|
4
|
-
/** @import { MessageQueue } from '@yongdall/connection' */
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* @param {string} url
|
|
8
|
-
* @returns {Promise<MessageQueue>}
|
|
9
|
-
*/
|
|
10
|
-
async function redis_default(url) {
|
|
11
|
-
const redis = new IORedis(url);
|
|
12
|
-
return {
|
|
13
|
-
async publish(channel, message) {
|
|
14
|
-
await redis.publish(channel, JSON.stringify(message));
|
|
15
|
-
},
|
|
16
|
-
async subscribe(channel, subscriber) {
|
|
17
|
-
redis.subscribe(channel, (err, count) => {});
|
|
18
|
-
redis.on("message", (messageChannel, message) => {
|
|
19
|
-
if (messageChannel !== channel) return;
|
|
20
|
-
try {
|
|
21
|
-
subscriber(JSON.parse(message));
|
|
22
|
-
} catch {}
|
|
23
|
-
});
|
|
24
|
-
return () => redis.unsubscribe(channel);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
//#endregion
|
|
30
|
-
export { redis_default as default };
|
|
31
|
-
//# sourceMappingURL=redis-CSe28ot7.mjs.map
|
package/redis-CSe28ot7.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"redis-CSe28ot7.mjs","names":[],"sources":["../../providers/mq-redis/redis.mjs"],"sourcesContent":["import IORedis from 'ioredis';\n/** @import { MessageQueue } from '@yongdall/connection' */\n\n/**\n * \n * @param {string} url \n * @returns {Promise<MessageQueue>}\n */\nexport default async function(url) {\n\n\n\tconst redis = new IORedis(url);\n\n\treturn {\n\t\tasync publish(channel, message) {\n\t\t\tawait redis.publish(channel, JSON.stringify(message));\n\t\t},\n\t\tasync subscribe(channel, subscriber) {\n\n\t\t\tredis.subscribe(channel, (err, count) => {\n\t\t\t\t// if (err) {\n\t\t\t\t// \tconsole.error(\"Failed to subscribe:\", err);\n\t\t\t\t// } else {\n\t\t\t\t// \tconsole.log(`Subscribed to ${count} channels.`);\n\t\t\t\t// }\n\t\t\t});\n\n\t\t\tredis.on(\"message\", (messageChannel, message) => {\n\t\t\t\tif (messageChannel !== channel) { return; }\n\t\t\t\ttry {\n\t\t\t\t\tsubscriber(JSON.parse(message));\n\t\t\t\t} catch {\n\n\t\t\t\t}\n\t\t\t});\n\t\t\treturn () => redis.unsubscribe(channel);\n\t\t}\n\t};\n}\n"],"mappings":";;;;;;;;;AAQA,6BAA8B,KAAK;CAGlC,MAAM,QAAQ,IAAI,QAAQ,IAAI;AAE9B,QAAO;EACN,MAAM,QAAQ,SAAS,SAAS;AAC/B,SAAM,MAAM,QAAQ,SAAS,KAAK,UAAU,QAAQ,CAAC;;EAEtD,MAAM,UAAU,SAAS,YAAY;AAEpC,SAAM,UAAU,UAAU,KAAK,UAAU,GAMvC;AAEF,SAAM,GAAG,YAAY,gBAAgB,YAAY;AAChD,QAAI,mBAAmB,QAAW;AAClC,QAAI;AACH,gBAAW,KAAK,MAAM,QAAQ,CAAC;YACxB;KAGP;AACF,gBAAa,MAAM,YAAY,QAAQ;;EAExC"}
|