@less-is-more/less-js 1.2.16 → 1.2.17
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/package.json +1 -1
- package/src/redis.js +35 -35
package/package.json
CHANGED
package/src/redis.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
const redis = require("redis");
|
|
2
|
-
const { promisify } = require("util");
|
|
3
2
|
|
|
4
3
|
module.exports = class Redis {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
static #client;
|
|
5
|
+
static #user;
|
|
6
|
+
static #password;
|
|
7
|
+
static #host;
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
static init(host, user, password) {
|
|
10
|
+
this.#host = host;
|
|
11
|
+
this.#user = user;
|
|
12
|
+
this.#password = password;
|
|
13
|
+
}
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
15
|
+
static async getInstance() {
|
|
16
|
+
if (!this.#client) {
|
|
17
|
+
if (this.#host) {
|
|
18
|
+
this.#client = await redis.createClient({
|
|
19
|
+
host: this.#host,
|
|
20
|
+
user: this.#user,
|
|
21
|
+
password: this.#password,
|
|
22
|
+
});
|
|
23
|
+
await this.#client.connect();
|
|
24
|
+
} else {
|
|
25
|
+
throw new Error("Redis not init");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return this.#client;
|
|
29
|
+
}
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
static async exec(name, ...args) {
|
|
32
|
+
let client = await Redis.getInstance();
|
|
33
|
+
return await client[name].bind(client).apply(undefined, args);
|
|
34
|
+
}
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
static formatKey(name, params = {}) {
|
|
37
|
+
let key = name;
|
|
38
|
+
for (let nKey in params) {
|
|
39
|
+
key += ":" + nKey + ":" + params[nKey];
|
|
40
|
+
}
|
|
41
|
+
return key;
|
|
42
|
+
}
|
|
43
43
|
};
|