@sebspark/promise-cache 2.0.5 → 2.0.7
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/dist/index.js +17 -16
- package/dist/index.mjs +17 -16
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -31,7 +31,6 @@ module.exports = __toCommonJS(src_exports);
|
|
|
31
31
|
var import_node_crypto = require("crypto");
|
|
32
32
|
|
|
33
33
|
// src/persistor.ts
|
|
34
|
-
var import_retry = require("@sebspark/retry");
|
|
35
34
|
var import_redis = require("redis");
|
|
36
35
|
|
|
37
36
|
// src/localMemory.ts
|
|
@@ -103,29 +102,31 @@ var Persistor = class {
|
|
|
103
102
|
}
|
|
104
103
|
}
|
|
105
104
|
async connect() {
|
|
106
|
-
|
|
107
|
-
interval: (x) => {
|
|
108
|
-
return x * 2 * 1e3;
|
|
109
|
-
},
|
|
110
|
-
maxRetries: 3,
|
|
111
|
-
retryCondition: () => {
|
|
112
|
-
var _a;
|
|
113
|
-
console.log(
|
|
114
|
-
`Connecting to redis... ${this.clientId}, ${(_a = this.redis) == null ? void 0 : _a.name}`
|
|
115
|
-
);
|
|
116
|
-
return true;
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
await (0, import_retry.retry)(() => this.startConnection(), settings);
|
|
105
|
+
await this.startConnection();
|
|
120
106
|
}
|
|
121
107
|
startConnection() {
|
|
122
108
|
return new Promise((resolve, reject) => {
|
|
123
|
-
this.client = CACHE_CLIENT(
|
|
109
|
+
this.client = CACHE_CLIENT({
|
|
110
|
+
...this.redis,
|
|
111
|
+
socket: {
|
|
112
|
+
reconnectStrategy: (retries, cause) => {
|
|
113
|
+
if (retries === 5) {
|
|
114
|
+
console.error("Error reconnecting... ", cause);
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
return retries * 1e3;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}).on("error", (err) => {
|
|
124
121
|
this.onError(err);
|
|
125
122
|
reject();
|
|
126
123
|
}).on("ready", () => {
|
|
127
124
|
this.onSuccess();
|
|
128
125
|
resolve(true);
|
|
126
|
+
}).on("reconnecting", () => {
|
|
127
|
+
console.log("reconnecting...", this.clientId);
|
|
128
|
+
}).on("end", () => {
|
|
129
|
+
console.log("end...", this.clientId);
|
|
129
130
|
});
|
|
130
131
|
return this.client.connect();
|
|
131
132
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
|
|
4
4
|
// src/persistor.ts
|
|
5
|
-
import { retry } from "@sebspark/retry";
|
|
6
5
|
import { createClient } from "redis";
|
|
7
6
|
|
|
8
7
|
// src/localMemory.ts
|
|
@@ -74,29 +73,31 @@ var Persistor = class {
|
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
75
|
async connect() {
|
|
77
|
-
|
|
78
|
-
interval: (x) => {
|
|
79
|
-
return x * 2 * 1e3;
|
|
80
|
-
},
|
|
81
|
-
maxRetries: 3,
|
|
82
|
-
retryCondition: () => {
|
|
83
|
-
var _a;
|
|
84
|
-
console.log(
|
|
85
|
-
`Connecting to redis... ${this.clientId}, ${(_a = this.redis) == null ? void 0 : _a.name}`
|
|
86
|
-
);
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
await retry(() => this.startConnection(), settings);
|
|
76
|
+
await this.startConnection();
|
|
91
77
|
}
|
|
92
78
|
startConnection() {
|
|
93
79
|
return new Promise((resolve, reject) => {
|
|
94
|
-
this.client = CACHE_CLIENT(
|
|
80
|
+
this.client = CACHE_CLIENT({
|
|
81
|
+
...this.redis,
|
|
82
|
+
socket: {
|
|
83
|
+
reconnectStrategy: (retries, cause) => {
|
|
84
|
+
if (retries === 5) {
|
|
85
|
+
console.error("Error reconnecting... ", cause);
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
return retries * 1e3;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}).on("error", (err) => {
|
|
95
92
|
this.onError(err);
|
|
96
93
|
reject();
|
|
97
94
|
}).on("ready", () => {
|
|
98
95
|
this.onSuccess();
|
|
99
96
|
resolve(true);
|
|
97
|
+
}).on("reconnecting", () => {
|
|
98
|
+
console.log("reconnecting...", this.clientId);
|
|
99
|
+
}).on("end", () => {
|
|
100
|
+
console.log("end...", this.clientId);
|
|
100
101
|
});
|
|
101
102
|
return this.client.connect();
|
|
102
103
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sebspark/promise-cache",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.7",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"tsconfig": "*"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"redis": "4.
|
|
22
|
+
"redis": "4.7.0",
|
|
23
23
|
"@sebspark/retry": "*"
|
|
24
24
|
}
|
|
25
25
|
}
|