@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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/redis.js +35 -35
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@less-is-more/less-js",
3
- "version": "1.2.16",
3
+ "version": "1.2.17",
4
4
  "description": "Fast develop kit for nodejs",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
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
- static #client;
6
- static #user;
7
- static #password;
8
- static #host;
4
+ static #client;
5
+ static #user;
6
+ static #password;
7
+ static #host;
9
8
 
10
- static init(host, user, password) {
11
- this.#host = host;
12
- this.#user = user;
13
- this.#password = password;
14
- }
9
+ static init(host, user, password) {
10
+ this.#host = host;
11
+ this.#user = user;
12
+ this.#password = password;
13
+ }
15
14
 
16
- static getInstance() {
17
- if (!this.#client) {
18
- if (this.#host) {
19
- this.#client = redis.createClient({
20
- host: this.#host,
21
- user: this.#user,
22
- password: this.#password,
23
- });
24
- } else {
25
- throw new Error("Redis not init");
26
- }
27
- }
28
- return this.#client;
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
- static async exec(name, ...args) {
32
- let client = Redis.getInstance();
33
- return await promisify(client[name]).bind(client).apply(undefined, args);
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
- static formatKey(name, params = {}) {
37
- let key = name;
38
- for (let nKey in params) {
39
- key += ":" + nKey + ":" + params[nKey];
40
- }
41
- return key;
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
  };