@bejibun/redis 0.1.17 → 0.1.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.
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
var _a;
|
|
2
1
|
import { defineValue, isEmpty, isNotEmpty } from "@bejibun/core";
|
|
3
2
|
import { RedisClient } from "bun";
|
|
4
3
|
import { EventEmitter } from "events";
|
|
5
4
|
import config from "../config/redis";
|
|
6
5
|
import RedisException from "../exceptions/RedisException";
|
|
7
|
-
class RedisBuilder {
|
|
6
|
+
export default class RedisBuilder {
|
|
7
|
+
static clients = {};
|
|
8
|
+
static emitter = new EventEmitter();
|
|
8
9
|
static connection(name) {
|
|
9
10
|
return {
|
|
10
11
|
del: (key) => this.del(key, name),
|
|
@@ -166,37 +167,33 @@ class RedisBuilder {
|
|
|
166
167
|
static ensureExitHooks() {
|
|
167
168
|
this.setupExitHooks();
|
|
168
169
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
170
|
+
static setupExitHooks = (() => {
|
|
171
|
+
let initialized = false;
|
|
172
|
+
return () => {
|
|
173
|
+
if (initialized)
|
|
174
|
+
return;
|
|
175
|
+
initialized = true;
|
|
176
|
+
const handleExit = async (signal) => {
|
|
177
|
+
try {
|
|
178
|
+
await RedisBuilder.disconnect();
|
|
179
|
+
console.log(`[Redis]: Disconnected on "${defineValue(signal, "exit")}".`);
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
console.error("[Redis]: Error during disconnect.", error.message);
|
|
183
|
+
}
|
|
184
|
+
finally {
|
|
185
|
+
process.exit(0);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
process.on("exit", async () => {
|
|
189
|
+
await handleExit();
|
|
190
|
+
});
|
|
191
|
+
process.on("SIGINT", async () => {
|
|
192
|
+
await handleExit("SIGINT");
|
|
193
|
+
});
|
|
194
|
+
process.on("SIGTERM", async () => {
|
|
195
|
+
await handleExit("SIGTERM");
|
|
196
|
+
});
|
|
190
197
|
};
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
});
|
|
194
|
-
process.on("SIGINT", async () => {
|
|
195
|
-
await handleExit("SIGINT");
|
|
196
|
-
});
|
|
197
|
-
process.on("SIGTERM", async () => {
|
|
198
|
-
await handleExit("SIGTERM");
|
|
199
|
-
});
|
|
200
|
-
};
|
|
201
|
-
})();
|
|
202
|
-
export default RedisBuilder;
|
|
198
|
+
})();
|
|
199
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bejibun/redis",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"description": "Redis for Bejibun Framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"type": "module",
|
|
23
23
|
"main": "./dist/index.js",
|
|
24
24
|
"module": "./dist/index.js",
|
|
25
|
-
"types": "./dist/
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
26
|
"exports": {
|
|
27
27
|
".": {
|
|
28
28
|
"import": "./dist/index.js",
|
|
29
|
-
"types": "./dist/
|
|
29
|
+
"types": "./dist/index.d.ts"
|
|
30
30
|
},
|
|
31
31
|
"./exceptions/*": {
|
|
32
32
|
"import": "./dist/exceptions/*.js",
|