@cap-js-community/common 0.3.1 → 0.3.2
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/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/src/redis-client/RedisClient.js +15 -4
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
|
6
6
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## Version 0.3.2 - 2025-11-05
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Rework redis client
|
|
13
|
+
|
|
8
14
|
## Version 0.3.1 - 2025-11-05
|
|
9
15
|
|
|
10
16
|
### Fixed
|
package/package.json
CHANGED
|
@@ -10,8 +10,9 @@ const TIMEOUT_SHUTDOWN = 2500;
|
|
|
10
10
|
class RedisClient {
|
|
11
11
|
#clusterClient = false;
|
|
12
12
|
#beforeCloseHandler;
|
|
13
|
-
constructor(name) {
|
|
13
|
+
constructor(name, env) {
|
|
14
14
|
this.name = name;
|
|
15
|
+
this.env = env || this.name;
|
|
15
16
|
this.log = cds.log(COMPONENT_NAME);
|
|
16
17
|
this.mainClientPromise = null;
|
|
17
18
|
this.subscriberClientPromise = null;
|
|
@@ -42,6 +43,11 @@ class RedisClient {
|
|
|
42
43
|
return this.mainClientPromise;
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
createAdditionalClientAndConnect(options) {
|
|
47
|
+
const redisClient = RedisClient.create(this.name + "-2", this.env);
|
|
48
|
+
return redisClient.createMainClientAndConnect(options);
|
|
49
|
+
}
|
|
50
|
+
|
|
45
51
|
async createClientAndConnect(options, errorHandlerCreateClient, isConnectionCheck) {
|
|
46
52
|
try {
|
|
47
53
|
const client = this.createClientBase(options);
|
|
@@ -98,7 +104,7 @@ class RedisClient {
|
|
|
98
104
|
|
|
99
105
|
createClientBase(redisOptions = {}) {
|
|
100
106
|
const { credentials, options } =
|
|
101
|
-
(this.
|
|
107
|
+
(this.env ? cds.env.requires[`redis-${this.env}`] : undefined) || cds.env.requires["redis"] || {};
|
|
102
108
|
const socket = {
|
|
103
109
|
host: credentials?.hostname ?? "127.0.0.1",
|
|
104
110
|
tls: !!credentials?.tls,
|
|
@@ -242,14 +248,19 @@ class RedisClient {
|
|
|
242
248
|
return this.#clusterClient;
|
|
243
249
|
}
|
|
244
250
|
|
|
245
|
-
static create(name = "default") {
|
|
251
|
+
static create(name = "default", env) {
|
|
252
|
+
env ??= name;
|
|
246
253
|
RedisClient._create ??= {};
|
|
247
254
|
if (!RedisClient._create[name]) {
|
|
248
|
-
RedisClient._create[name] = new RedisClient(name);
|
|
255
|
+
RedisClient._create[name] = new RedisClient(name, env);
|
|
249
256
|
}
|
|
250
257
|
return RedisClient._create[name];
|
|
251
258
|
}
|
|
252
259
|
|
|
260
|
+
static default(name) {
|
|
261
|
+
return RedisClient.create(name);
|
|
262
|
+
}
|
|
263
|
+
|
|
253
264
|
static async closeAllClients() {
|
|
254
265
|
for (const entry of Object.values(RedisClient._create || {})) {
|
|
255
266
|
await entry.closeClients();
|