dt-common-device 2.0.4 → 2.0.6
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,6 +1,6 @@
|
|
|
1
1
|
export declare class RedisUtils {
|
|
2
|
-
private client;
|
|
3
|
-
hget(key: string, field: string): Promise<
|
|
2
|
+
private readonly client;
|
|
3
|
+
hget(key: string, field: string): Promise<any>;
|
|
4
4
|
hset(key: string, field: string, value: string): Promise<number>;
|
|
5
5
|
hdel(key: string, ...fields: string[]): Promise<number>;
|
|
6
6
|
exists(key: string): Promise<number>;
|
|
@@ -52,7 +52,11 @@ let RedisUtils = (() => {
|
|
|
52
52
|
}
|
|
53
53
|
async hget(key, field) {
|
|
54
54
|
try {
|
|
55
|
-
|
|
55
|
+
const value = await this.client.hget(key, field);
|
|
56
|
+
if (!value) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
return JSON.parse(value);
|
|
56
60
|
}
|
|
57
61
|
catch (error) {
|
|
58
62
|
console.error(`Error getting value for key ${key}:`, error);
|
|
@@ -72,7 +76,7 @@ let RedisUtils = (() => {
|
|
|
72
76
|
// return this.client.del(key);
|
|
73
77
|
// }
|
|
74
78
|
async hdel(key, ...fields) {
|
|
75
|
-
return this.client.hdel(key, ...fields);
|
|
79
|
+
return await this.client.hdel(key, ...fields);
|
|
76
80
|
}
|
|
77
81
|
// async get(key: string): Promise<string | null> {
|
|
78
82
|
// try {
|
|
@@ -93,7 +97,7 @@ let RedisUtils = (() => {
|
|
|
93
97
|
} */
|
|
94
98
|
async exists(key) {
|
|
95
99
|
try {
|
|
96
|
-
return this.client.exists(key);
|
|
100
|
+
return await this.client.exists(key);
|
|
97
101
|
}
|
|
98
102
|
catch (error) {
|
|
99
103
|
console.error(`Error checking existence for key ${key}:`, error);
|
|
@@ -102,7 +106,7 @@ let RedisUtils = (() => {
|
|
|
102
106
|
}
|
|
103
107
|
async expire(key, seconds) {
|
|
104
108
|
try {
|
|
105
|
-
return this.client.expire(key, seconds);
|
|
109
|
+
return await this.client.expire(key, seconds);
|
|
106
110
|
}
|
|
107
111
|
catch (error) {
|
|
108
112
|
console.error(`Error setting expiration for key ${key}:`, error);
|
package/package.json
CHANGED
package/src/utils/redis.utils.ts
CHANGED
|
@@ -3,11 +3,15 @@ import { getRedisClient } from "../db/redis";
|
|
|
3
3
|
|
|
4
4
|
@Service()
|
|
5
5
|
export class RedisUtils {
|
|
6
|
-
private client = getRedisClient(); // singleton Redis client instance
|
|
6
|
+
private readonly client = getRedisClient(); // singleton Redis client instance
|
|
7
7
|
|
|
8
|
-
async hget(key: string, field: string): Promise<
|
|
8
|
+
async hget(key: string, field: string): Promise<any> {
|
|
9
9
|
try {
|
|
10
|
-
|
|
10
|
+
const value: string | null = await this.client.hget(key, field);
|
|
11
|
+
if (!value) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
return JSON.parse(value);
|
|
11
15
|
} catch (error) {
|
|
12
16
|
console.error(`Error getting value for key ${key}:`, error);
|
|
13
17
|
throw error;
|
|
@@ -28,7 +32,7 @@ export class RedisUtils {
|
|
|
28
32
|
// }
|
|
29
33
|
|
|
30
34
|
async hdel(key: string, ...fields: string[]): Promise<number> {
|
|
31
|
-
return this.client.hdel(key, ...fields);
|
|
35
|
+
return await this.client.hdel(key, ...fields);
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
// async get(key: string): Promise<string | null> {
|
|
@@ -52,7 +56,7 @@ export class RedisUtils {
|
|
|
52
56
|
|
|
53
57
|
async exists(key: string): Promise<number> {
|
|
54
58
|
try {
|
|
55
|
-
return this.client.exists(key);
|
|
59
|
+
return await this.client.exists(key);
|
|
56
60
|
} catch (error) {
|
|
57
61
|
console.error(`Error checking existence for key ${key}:`, error);
|
|
58
62
|
throw error;
|
|
@@ -61,7 +65,7 @@ export class RedisUtils {
|
|
|
61
65
|
|
|
62
66
|
async expire(key: string, seconds: number): Promise<any> {
|
|
63
67
|
try {
|
|
64
|
-
return this.client.expire(key, seconds);
|
|
68
|
+
return await this.client.expire(key, seconds);
|
|
65
69
|
} catch (error) {
|
|
66
70
|
console.error(`Error setting expiration for key ${key}:`, error);
|
|
67
71
|
throw error;
|