@mulingai-npm/redis 2.0.2 → 2.0.4

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.
@@ -2,6 +2,7 @@ import { RedisClient } from '../redis-client';
2
2
  export type StepStatus = 'INIT' | 'DISCARDED' | 'READY' | 'USED';
3
3
  export type SttProvider = 'azure' | 'whisper' | 'google' | 'aws';
4
4
  export type MulingstreamChunkData = {
5
+ roomId: string;
5
6
  chunkNumber: number;
6
7
  language: string;
7
8
  sttProviders: SttProvider[];
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MulingstreamChunkManager = void 0;
4
4
  const EXPIRATION = 12 * 60 * 60; // 12 hours in seconds
5
- const ROOM_ARRAY_LENGTH = 5; // keep only the last 5 elements
5
+ const ROOM_ARRAY_LENGTH = 50; // keep only the last 5 elements
6
6
  class MulingstreamChunkManager {
7
7
  constructor(redisClient) {
8
8
  this.redisClient = redisClient;
@@ -42,8 +42,9 @@ class MulingstreamChunkManager {
42
42
  async getMulingstreamChunksByRoom(roomId) {
43
43
  // JSON.GET [roomId] .
44
44
  const chunks = await this.redisClient.jsonGet(`[${roomId}]`, '.');
45
- if (chunks === null)
46
- return null; // room not found
45
+ if (chunks === null) {
46
+ return null;
47
+ }
47
48
  return chunks;
48
49
  }
49
50
  /**
@@ -59,8 +60,8 @@ class MulingstreamChunkManager {
59
60
  async addMulingstreamChunk(params) {
60
61
  const { roomId, chunkNumber, language, start, end, duration, isFirst, isLast, theme, sttProviders, targetLanguages } = params;
61
62
  // ensure we only keep the last 5 elements
62
- const currentLength = await this.redisClient.jsonArrPop(`[${roomId}]`, '.', 0);
63
- if (typeof currentLength === 'number' && currentLength >= ROOM_ARRAY_LENGTH) {
63
+ const currentLength = await this.redisClient.jsonArrLen(`[${roomId}]`, '.');
64
+ if ((currentLength !== null && currentLength !== void 0 ? currentLength : 0) >= ROOM_ARRAY_LENGTH) {
64
65
  // remove the oldest (front of the array)
65
66
  await this.redisClient.jsonArrPop(`[${roomId}]`, '.', 0);
66
67
  }
@@ -97,6 +98,7 @@ class MulingstreamChunkManager {
97
98
  };
98
99
  }
99
100
  const newChunk = {
101
+ roomId,
100
102
  chunkNumber,
101
103
  language,
102
104
  sttProviders,
@@ -23,5 +23,6 @@ export declare class RedisClient {
23
23
  jsonGet<T>(key: string, path: string): Promise<T | null>;
24
24
  jsonDel(key: string, path: string): Promise<number>;
25
25
  jsonArrAppend<T>(key: string, path: string, ...values: T[]): Promise<number>;
26
+ jsonArrLen(key: string, path: string): Promise<number | null>;
26
27
  jsonArrPop(key: string, path: string, index?: number): Promise<any>;
27
28
  }
@@ -81,6 +81,10 @@ class RedisClient {
81
81
  const result = await this.client.call('JSON.ARRAPPEND', key, path, ...stringifiedValues);
82
82
  return Number(result);
83
83
  }
84
+ async jsonArrLen(key, path) {
85
+ const result = await this.client.call('JSON.ARRLEN', key, path);
86
+ return result === null ? null : Number(result);
87
+ }
84
88
  async jsonArrPop(key, path, index) {
85
89
  if (index !== undefined) {
86
90
  return this.client.call('JSON.ARRPOP', key, path, index);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mulingai-npm/redis",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {