Skip to content

Commit cc5d683

Browse files
committed
local_cache_items
1 parent 3f8f10d commit cc5d683

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

.github/workflows/docker-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ jobs:
3636
push: true
3737
platforms: linux/amd64
3838
# tags: cdnbye/cbsignal_uws:latest
39-
tags: cdnbye/cbsignal_uws:5.4.5
39+
tags: cdnbye/cbsignal_uws:5.4.6

lib/broker/redis.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,34 @@ let stats = {
1414
curCount: 0,
1515
}
1616

17-
async function connectUrl(_selfAddr, url) {
17+
async function connectUrl(_selfAddr, url, maxCacheItems) {
1818
redisCli = new Redis(url);
19-
initRedis(redisCli, _selfAddr);
19+
initRedis(redisCli, _selfAddr, maxCacheItems);
2020
}
2121

22-
async function connect(_selfAddr, host, port, username, password, db = 0) {
22+
async function connect(_selfAddr, host, port, username, password, db = 0, maxCacheItems) {
2323
redisCli = new Redis({
2424
port: port, // Redis port
2525
host: host, // Redis host
2626
username: username, // needs Redis >= 6
2727
password: password,
2828
db: db, // Defaults to 0
2929
});
30-
initRedis(redisCli, _selfAddr);
30+
initRedis(redisCli, _selfAddr, maxCacheItems);
3131
}
3232

33-
async function connectCluster(_selfAddr, addrs, username, password) {
33+
async function connectCluster(_selfAddr, addrs, username, password, maxCacheItems) {
3434
redisCli = new Redis.Cluster(addrs, {
3535
redisOptions: {
3636
username,
3737
password,
3838
},
3939
});
40-
initRedis(redisCli, _selfAddr);
40+
initRedis(redisCli, _selfAddr, maxCacheItems);
4141
}
4242

43-
function initRedis(redisCli, _selfAddr) {
44-
initCache();
43+
function initRedis(redisCli, _selfAddr, maxCacheItems) {
44+
initCache(maxCacheItems);
4545
isAlive = true;
4646
selfAddr = _selfAddr;
4747
}
@@ -134,9 +134,16 @@ async function blockPopMQ(cli, timeout, addr) {
134134
return result[1]
135135
}
136136

137-
function initCache() {
137+
function initCache(max = 100000) {
138+
if (max <= 0) {
139+
cache = {
140+
get: () => {},
141+
set: () => {},
142+
}
143+
return
144+
}
138145
const options = {
139-
max: 100000,
146+
max,
140147

141148
// for use with tracking overall storage size
142149
// maxSize: 5000,

lib/worker.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ const startWorker = async (config = {}) => {
4848
}
4949
}
5050
if (config.redis) {
51-
const { url, host, port, dbname, is_cluster: isCluster, cluster, password, username } = config.redis
51+
const { url, host, port, dbname, is_cluster: isCluster, cluster, password, username, local_cache_items } = config.redis
5252
if (url) {
5353
logger.info(`start connect redis url ${url}`);
54-
await redis.connectUrl(selfAddr, url);
54+
await redis.connectUrl(selfAddr, url, local_cache_items);
5555
} else if (isCluster) {
5656
logger.info(`start connect redis cluster`);
57-
await redis.connectCluster(selfAddr, cluster, username, password);
57+
await redis.connectCluster(selfAddr, cluster, username, password, local_cache_items);
5858
} else {
5959
logger.info(`start connect redis ${host}:${port} db ${dbname}`);
60-
await redis.connect(selfAddr, host, port, username, password, dbname);
60+
await redis.connect(selfAddr, host, port, username, password, dbname, local_cache_items);
6161
}
6262
logger.info(`redis connected`);
6363
redis.updateClientCount(hub.numClient);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cbsignal_uws",
3-
"version": "5.4.5",
3+
"version": "5.4.6",
44
"description": "SwarmCloud signaling server using uWebSockets.js",
55
"main": "index.js",
66
"bin": "index.js",

0 commit comments

Comments
 (0)