Skip to content

Commit 936be8c

Browse files
committed
Redis
1 parent 1c38350 commit 936be8c

File tree

5 files changed

+63
-87
lines changed

5 files changed

+63
-87
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8-
## Version 1.9.1 - 2025-12-xx
8+
## Version 1.9.1 - 2025-11-05
99

1010
### Fixed
1111

12-
- tbd
12+
- Rework redis client
1313

1414
## Version 1.9.0 - 2025-11-03
1515

package-lock.json

Lines changed: 54 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"audit": "npm audit --only=prod"
4444
},
4545
"dependencies": {
46-
"@cap-js-community/common": "^0.3.0",
46+
"@cap-js-community/common": "^0.3.2",
4747
"socket.io": "^4.8.1",
4848
"socket.io-client": "^4.8.1",
4949
"ws": "^8.18.3"
@@ -52,12 +52,12 @@
5252
"@cap-js-community/websocket": "./",
5353
"@cap-js/cds-test": "^0.4.0",
5454
"@cap-js/sqlite": "^2.0.4",
55-
"@eslint/js": "^9.38.0",
55+
"@eslint/js": "^9.39.1",
5656
"@sap/cds": "^9.4.4",
5757
"@sap/cds-dk": "^9.4.2",
5858
"@socket.io/redis-adapter": "^8.3.0",
5959
"@socket.io/redis-streams-adapter": "^0.2.2",
60-
"eslint": "^9.38.0",
60+
"eslint": "^9.39.1",
6161
"eslint-config-prettier": "^10.1.8",
6262
"eslint-plugin-jest": "^29.0.1",
6363
"eslint-plugin-n": "^17.21.3",

src/index.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
const cds = require("@sap/cds");
44

55
const SocketServer = require("./socket/base");
6-
const redis = require("./redis");
76

87
const LOG = cds.log("websocket");
9-
const TIMEOUT_SHUTDOWN = 2500;
108

119
const WebSocketAction = {
1210
Connect: "wsConnect",
@@ -27,9 +25,6 @@ const collectServicesAndMountAdapter = (srv, options) => {
2725
options.services = services;
2826
serveWebSocketServer(options);
2927
});
30-
cds.on("shutdown", async () => {
31-
await shutdownWebSocketServer();
32-
});
3328
}
3429
services[srv.name] = srv;
3530
};
@@ -126,26 +121,6 @@ async function initWebSocketServer(server, path) {
126121
}
127122
}
128123

129-
async function shutdownWebSocketServer() {
130-
return await new Promise((resolve, reject) => {
131-
const timeoutRef = setTimeout(() => {
132-
clearTimeout(timeoutRef);
133-
LOG?.info("Shutdown timeout reached!");
134-
resolve();
135-
}, TIMEOUT_SHUTDOWN);
136-
redis
137-
.closeClients()
138-
.then((result) => {
139-
clearTimeout(timeoutRef);
140-
resolve(result);
141-
})
142-
.catch((err) => {
143-
clearTimeout(timeoutRef);
144-
reject(err);
145-
});
146-
});
147-
}
148-
149124
function normalizeServicePath(servicePath, protocolPath) {
150125
if (servicePath.startsWith(`${protocolPath}/`)) {
151126
return servicePath.substring(`${protocolPath}/`.length);

src/redis/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const { RedisClient } = require("@cap-js-community/common");
66
const LOG = cds.log("websocket/redis");
77
const IS_ON_CF = process.env.USER === "vcap";
88

9-
const redisClient = RedisClient.default("websocket");
9+
const redisClient = RedisClient.create("websocket");
10+
const redisClientSecondary = RedisClient.create("websocket-secondary", "websocket");
1011

1112
async function connectionCheck(options) {
1213
const adapterActive = options?.active !== false;
@@ -28,11 +29,11 @@ async function createPrimaryClientAndConnect(options) {
2829
}
2930

3031
async function createSecondaryClientAndConnect(options) {
31-
return await redisClient.createAdditionalClientAndConnect(options?.config);
32+
return await redisClientSecondary.createMainClientAndConnect(options?.config);
3233
}
3334

3435
async function closeClients() {
35-
return await redisClient.closeClients();
36+
return await RedisClient.closeAllClients();
3637
}
3738

3839
module.exports = {

0 commit comments

Comments
 (0)