@mulingai-npm/redis 3.24.1 → 3.26.0

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,5 +2,6 @@ export declare enum RedisDatabase {
2
2
  MULINGSTREAM_LISTENER = 0,
3
3
  MULINGSTREAM_CHUNK = 1,
4
4
  MULINGSTREAM_SPEAKER = 2,
5
- CONTENT_DATA = 3
5
+ CONTENT_DATA = 3,
6
+ ACCOUNT_DATA = 4
6
7
  }
@@ -7,4 +7,5 @@ var RedisDatabase;
7
7
  RedisDatabase[RedisDatabase["MULINGSTREAM_CHUNK"] = 1] = "MULINGSTREAM_CHUNK";
8
8
  RedisDatabase[RedisDatabase["MULINGSTREAM_SPEAKER"] = 2] = "MULINGSTREAM_SPEAKER";
9
9
  RedisDatabase[RedisDatabase["CONTENT_DATA"] = 3] = "CONTENT_DATA";
10
+ RedisDatabase[RedisDatabase["ACCOUNT_DATA"] = 4] = "ACCOUNT_DATA";
10
11
  })(RedisDatabase = exports.RedisDatabase || (exports.RedisDatabase = {}));
@@ -0,0 +1,53 @@
1
+ import { RedisClient } from '../redis-client';
2
+ /**
3
+ * Cached user profile data
4
+ * Includes account verification status + billing consumption status
5
+ */
6
+ export interface CachedUserProfile {
7
+ userId: string;
8
+ email: string;
9
+ name: string | null;
10
+ preferredLanguage: string;
11
+ isEmailVerified: boolean;
12
+ isPhoneVerified: boolean;
13
+ isProfileActivated: boolean;
14
+ canConsume: boolean;
15
+ cachedAt: string;
16
+ }
17
+ /**
18
+ * Redis manager for caching user profile data
19
+ *
20
+ * Cache Strategy:
21
+ * - Cache on: sign in, profile fetch, profile change
22
+ * - Invalidate on: email verification, profile update, account deletion
23
+ * - TTL: 24 hours (but usually invalidated before expiry)
24
+ *
25
+ * Usage:
26
+ * - auth-service: cache on sign in / profile fetch
27
+ * - auth-service: invalidate + re-cache on email verification
28
+ * - speaker-realtime-service: get cached profile on speaker join
29
+ * - pipeline-service: check canConsume during recording
30
+ */
31
+ export declare class UserProfileManager {
32
+ private redisClient;
33
+ constructor(redisClient: RedisClient);
34
+ private buildKey;
35
+ /**
36
+ * Cache user profile data
37
+ */
38
+ setUserProfile(profile: Omit<CachedUserProfile, 'cachedAt'>): Promise<void>;
39
+ /**
40
+ * Get cached user profile
41
+ * Returns null if not cached (caller should fetch from DB and cache)
42
+ */
43
+ getUserProfile(userId: string): Promise<CachedUserProfile | null>;
44
+ /**
45
+ * Invalidate (delete) user profile cache
46
+ * Call before re-caching on profile changes
47
+ */
48
+ invalidateUserProfile(userId: string): Promise<void>;
49
+ /**
50
+ * Check if user profile is cached
51
+ */
52
+ hasUserProfile(userId: string): Promise<boolean>;
53
+ }
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UserProfileManager = void 0;
4
+ // Cache for 24 hours - invalidated on profile changes
5
+ const CACHE_TTL = 24 * 60 * 60;
6
+ /**
7
+ * Redis manager for caching user profile data
8
+ *
9
+ * Cache Strategy:
10
+ * - Cache on: sign in, profile fetch, profile change
11
+ * - Invalidate on: email verification, profile update, account deletion
12
+ * - TTL: 24 hours (but usually invalidated before expiry)
13
+ *
14
+ * Usage:
15
+ * - auth-service: cache on sign in / profile fetch
16
+ * - auth-service: invalidate + re-cache on email verification
17
+ * - speaker-realtime-service: get cached profile on speaker join
18
+ * - pipeline-service: check canConsume during recording
19
+ */
20
+ class UserProfileManager {
21
+ constructor(redisClient) {
22
+ this.redisClient = redisClient;
23
+ }
24
+ buildKey(userId) {
25
+ return `user:${userId}:profile`;
26
+ }
27
+ /**
28
+ * Cache user profile data
29
+ */
30
+ async setUserProfile(profile) {
31
+ const key = this.buildKey(profile.userId);
32
+ const data = {
33
+ ...profile,
34
+ cachedAt: new Date().toISOString()
35
+ };
36
+ await this.redisClient.set(key, JSON.stringify(data));
37
+ await this.redisClient.expire(key, CACHE_TTL);
38
+ }
39
+ /**
40
+ * Get cached user profile
41
+ * Returns null if not cached (caller should fetch from DB and cache)
42
+ */
43
+ async getUserProfile(userId) {
44
+ const key = this.buildKey(userId);
45
+ const data = await this.redisClient.get(key);
46
+ if (data === null) {
47
+ return null;
48
+ }
49
+ try {
50
+ return JSON.parse(data);
51
+ }
52
+ catch {
53
+ await this.redisClient.del(key);
54
+ return null;
55
+ }
56
+ }
57
+ /**
58
+ * Invalidate (delete) user profile cache
59
+ * Call before re-caching on profile changes
60
+ */
61
+ async invalidateUserProfile(userId) {
62
+ const key = this.buildKey(userId);
63
+ await this.redisClient.del(key);
64
+ }
65
+ /**
66
+ * Check if user profile is cached
67
+ */
68
+ async hasUserProfile(userId) {
69
+ const key = this.buildKey(userId);
70
+ return (await this.redisClient.exists(key)) === 1;
71
+ }
72
+ }
73
+ exports.UserProfileManager = UserProfileManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mulingai-npm/redis",
3
- "version": "3.24.1",
3
+ "version": "3.26.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {