@mulingai-npm/redis 3.6.0 → 3.7.1

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.
@@ -1,5 +1,6 @@
1
1
  export declare enum RedisDatabase {
2
2
  MULINGSTREAM_LISTENER = 0,
3
3
  MULINGSTREAM_CHUNK = 1,
4
- MULINGSTREAM_SPEAKER = 2
4
+ MULINGSTREAM_SPEAKER = 2,
5
+ CONTENT_DATA = 3
5
6
  }
@@ -6,4 +6,5 @@ var RedisDatabase;
6
6
  RedisDatabase[RedisDatabase["MULINGSTREAM_LISTENER"] = 0] = "MULINGSTREAM_LISTENER";
7
7
  RedisDatabase[RedisDatabase["MULINGSTREAM_CHUNK"] = 1] = "MULINGSTREAM_CHUNK";
8
8
  RedisDatabase[RedisDatabase["MULINGSTREAM_SPEAKER"] = 2] = "MULINGSTREAM_SPEAKER";
9
+ RedisDatabase[RedisDatabase["CONTENT_DATA"] = 3] = "CONTENT_DATA";
9
10
  })(RedisDatabase = exports.RedisDatabase || (exports.RedisDatabase = {}));
@@ -21,9 +21,5 @@ export declare class MulingstreamListenerManager {
21
21
  updateNameLanguage(listenerIdOrToken: string, name: string, language: string): Promise<boolean>;
22
22
  updateSocketId(listenerIdOrToken: string, socketId: string): Promise<boolean>;
23
23
  getTargetSocketIdsByRoomLanguage(roomId: string, language: string): Promise<string[]>;
24
- /**
25
- * Returns an array of unique languages for the given room, from highest frequency to lowest.
26
- * If a listener has no language (empty string / undefined), it is ignored.
27
- */
28
24
  getUniqueLanguagesByRoom(roomId: string): Promise<string[]>;
29
25
  }
@@ -139,10 +139,6 @@ class MulingstreamListenerManager {
139
139
  });
140
140
  return filteredListeners.map((listener) => listener.socketId);
141
141
  }
142
- /**
143
- * Returns an array of unique languages for the given room, from highest frequency to lowest.
144
- * If a listener has no language (empty string / undefined), it is ignored.
145
- */
146
142
  async getUniqueLanguagesByRoom(roomId) {
147
143
  // 1) Fetch all listeners for the room.
148
144
  // (This includes inactive ones, but feel free to filter out isActive === false if you only want active ones.)
@@ -15,11 +15,7 @@ export declare class MulingstreamSpeakerManager {
15
15
  private redisClient;
16
16
  constructor(redisClient: RedisClient);
17
17
  private buildLockKey;
18
- /** Try to claim the speaker slot for this room.
19
- * @returns true when the lock was acquired, false if someone else holds it.
20
- */
21
18
  acquireRoomLock(roomId: string, socketId: string, ttl?: number): Promise<boolean>;
22
- /** Release the lock if we still own it. */
23
19
  releaseRoomLock(roomId: string, socketId: string): Promise<void>;
24
20
  private parseHash;
25
21
  private serialize;
@@ -7,19 +7,12 @@ class MulingstreamSpeakerManager {
7
7
  constructor(redisClient) {
8
8
  this.redisClient = redisClient;
9
9
  }
10
- /* ------------------------------------------------------------------ */
11
- /* One-speaker-per-room locking helpers */
12
- /* ------------------------------------------------------------------ */
13
10
  buildLockKey(roomId) {
14
11
  return `room:${roomId}:speaker_lock`;
15
12
  }
16
- /** Try to claim the speaker slot for this room.
17
- * @returns true when the lock was acquired, false if someone else holds it.
18
- */
19
13
  async acquireRoomLock(roomId, socketId, ttl = LOCK_TTL) {
20
14
  return this.redisClient.setNxEx(this.buildLockKey(roomId), socketId, ttl);
21
15
  }
22
- /** Release the lock if we still own it. */
23
16
  async releaseRoomLock(roomId, socketId) {
24
17
  const lockKey = this.buildLockKey(roomId);
25
18
  const current = await this.redisClient.get(lockKey);
@@ -27,9 +20,6 @@ class MulingstreamSpeakerManager {
27
20
  await this.redisClient.del(lockKey);
28
21
  }
29
22
  }
30
- /* ------------------------------------------------------------------ */
31
- /* Speaker CRUD + queries */
32
- /* ------------------------------------------------------------------ */
33
23
  parseHash(hash) {
34
24
  return {
35
25
  speakerId: hash.speakerId,
@@ -210,7 +200,7 @@ class MulingstreamSpeakerManager {
210
200
  this.redisClient.srem(`room:${roomId}:speakers`, speakerId),
211
201
  this.redisClient.srem(`user:${userId}:speakers`, speakerId),
212
202
  this.redisClient.del(`socket:${socketId}:speaker`),
213
- this.redisClient.del(this.buildLockKey(roomId)) // ensure lock clears
203
+ this.redisClient.del(this.buildLockKey(roomId))
214
204
  ]);
215
205
  }
216
206
  }
@@ -5,18 +5,10 @@ export interface RedisConfig {
5
5
  password?: string;
6
6
  db: number;
7
7
  }
8
- /**
9
- * Thin wrapper around ioredis that exposes exactly the helpers used by the two
10
- * managers. All helpers are 1-to-1 pass-through so there is no behavioural
11
- * change – this merely centralises typing and keeps the rest of the codebase
12
- * clean.
13
- */
14
8
  export declare class RedisClient {
15
9
  private client;
16
10
  constructor(config: RedisConfig);
17
11
  set(key: string, value: string): Promise<void>;
18
- /** Atomic SET with NX + EX.
19
- * @returns true if the key was set, false when it already existed */
20
12
  setNxEx(key: string, value: string, expireSeconds: number): Promise<boolean>;
21
13
  get(key: string): Promise<string | null>;
22
14
  del(key: string): Promise<number>;
@@ -5,12 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.RedisClient = void 0;
7
7
  const ioredis_1 = __importDefault(require("ioredis"));
8
- /**
9
- * Thin wrapper around ioredis that exposes exactly the helpers used by the two
10
- * managers. All helpers are 1-to-1 pass-through so there is no behavioural
11
- * change – this merely centralises typing and keeps the rest of the codebase
12
- * clean.
13
- */
14
8
  class RedisClient {
15
9
  constructor(config) {
16
10
  this.client = new ioredis_1.default({
@@ -23,14 +17,9 @@ class RedisClient {
23
17
  console.error('Redis error:', err);
24
18
  });
25
19
  }
26
- /* ----------------------------------------------------------------------- */
27
- /* Primitive string helpers */
28
- /* ----------------------------------------------------------------------- */
29
20
  async set(key, value) {
30
21
  await this.client.set(key, value);
31
22
  }
32
- /** Atomic SET with NX + EX.
33
- * @returns true if the key was set, false when it already existed */
34
23
  async setNxEx(key, value, expireSeconds) {
35
24
  // correct order: 'EX', ttl, 'NX'
36
25
  const res = (await this.client.set(key, value, 'EX', expireSeconds, 'NX'));
@@ -48,9 +37,6 @@ class RedisClient {
48
37
  async expire(key, seconds) {
49
38
  return this.client.expire(key, seconds);
50
39
  }
51
- /* ----------------------------------------------------------------------- */
52
- /* Set helpers */
53
- /* ----------------------------------------------------------------------- */
54
40
  async sadd(key, ...values) {
55
41
  return this.client.sadd(key, values);
56
42
  }
@@ -60,18 +46,12 @@ class RedisClient {
60
46
  async smembers(key) {
61
47
  return this.client.smembers(key);
62
48
  }
63
- /* ----------------------------------------------------------------------- */
64
- /* Hash helpers */
65
- /* ----------------------------------------------------------------------- */
66
49
  async hset(key, data) {
67
50
  return this.client.hset(key, data);
68
51
  }
69
52
  async hgetall(key) {
70
53
  return this.client.hgetall(key);
71
54
  }
72
- /* ----------------------------------------------------------------------- */
73
- /* Sorted-set helpers */
74
- /* ----------------------------------------------------------------------- */
75
55
  async zadd(key, score, member) {
76
56
  return this.client.zadd(key, score, member);
77
57
  }
@@ -87,24 +67,15 @@ class RedisClient {
87
67
  async zrem(key, ...members) {
88
68
  return this.client.zrem(key, members);
89
69
  }
90
- /* ----------------------------------------------------------------------- */
91
- /* Scan (pattern search) */
92
- /* ----------------------------------------------------------------------- */
93
70
  async scan(cursor, pattern, count = 1000) {
94
71
  return this.client.scan(cursor, 'MATCH', pattern, 'COUNT', count);
95
72
  }
96
73
  async keys(pattern) {
97
74
  return this.client.keys(pattern);
98
75
  }
99
- /* ----------------------------------------------------------------------- */
100
- /* Pipeline */
101
- /* ----------------------------------------------------------------------- */
102
76
  pipeline() {
103
77
  return this.client.pipeline();
104
78
  }
105
- /* ----------------------------------------------------------------------- */
106
- /* Misc */
107
- /* ----------------------------------------------------------------------- */
108
79
  async unlink(...keys) {
109
80
  // unlink exists on Redis ≥4 and is supported by ioredis but not typed in
110
81
  // older versions – we cast to any.
@@ -112,7 +83,6 @@ class RedisClient {
112
83
  // @ts-ignore – runtime command exists even if typings lag behind.
113
84
  return this.client.unlink(...keys);
114
85
  }
115
- /* JSON commands (RedisJSON module) -------------------------------------- */
116
86
  async jsonSet(key, path, value) {
117
87
  const result = await this.client.call('JSON.SET', key, path, JSON.stringify(value));
118
88
  return result;
@@ -135,9 +105,6 @@ class RedisClient {
135
105
  async jsonArrPop(key, path, index) {
136
106
  return index !== undefined ? this.client.call('JSON.ARRPOP', key, path, index) : this.client.call('JSON.ARRPOP', key, path);
137
107
  }
138
- /* ----------------------------------------------------------------------- */
139
- /* Dangerous! – flush helpers */
140
- /* ----------------------------------------------------------------------- */
141
108
  async flushAll() {
142
109
  console.warn('Flushing all Redis data!');
143
110
  return this.client.flushall();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mulingai-npm/redis",
3
- "version": "3.6.0",
3
+ "version": "3.7.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {