@vasrefil/api-toolkit 1.0.30 → 1.0.31
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.
- package/dist/redis/redis.d.ts +9 -4
- package/dist/redis/redis.js +29 -5
- package/package.json +1 -1
package/dist/redis/redis.d.ts
CHANGED
|
@@ -3,6 +3,10 @@ declare class Redis_ {
|
|
|
3
3
|
private className;
|
|
4
4
|
init: () => Promise<void>;
|
|
5
5
|
exists: (key: string) => Promise<number>;
|
|
6
|
+
expire: (dto: {
|
|
7
|
+
key: string;
|
|
8
|
+
expireIn: number | string;
|
|
9
|
+
}) => Promise<number>;
|
|
6
10
|
set_multiple_hash: (key: string, pairs: any) => Promise<"OK">;
|
|
7
11
|
set_hash: (payload: {
|
|
8
12
|
key: string;
|
|
@@ -16,17 +20,18 @@ declare class Redis_ {
|
|
|
16
20
|
delete_hash: (payload: {
|
|
17
21
|
key: string;
|
|
18
22
|
field: string;
|
|
19
|
-
}) => Promise<
|
|
23
|
+
}) => Promise<{}>;
|
|
20
24
|
fetch_hashes: (key: string) => Promise<Record<string, string>>;
|
|
21
25
|
set_item: (payload: {
|
|
22
26
|
key: string;
|
|
23
27
|
value: any;
|
|
24
28
|
}) => Promise<"OK">;
|
|
25
29
|
get_item: (key: string) => Promise<any>;
|
|
26
|
-
|
|
30
|
+
update_item: (payload: {
|
|
27
31
|
key: string;
|
|
28
|
-
|
|
29
|
-
}) => Promise<
|
|
32
|
+
value: any;
|
|
33
|
+
}) => Promise<"OK">;
|
|
34
|
+
delete_item: (key: string) => Promise<{}>;
|
|
30
35
|
set_list: (payload: {
|
|
31
36
|
key: string;
|
|
32
37
|
values: any[];
|
package/dist/redis/redis.js
CHANGED
|
@@ -27,6 +27,15 @@ class Redis_ {
|
|
|
27
27
|
throw error;
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
|
+
this.expire = async (dto) => {
|
|
31
|
+
try {
|
|
32
|
+
const resp = await this.client.expire(dto.key, dto.expireIn);
|
|
33
|
+
return resp;
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
30
39
|
this.set_multiple_hash = async (key, pairs) => {
|
|
31
40
|
try {
|
|
32
41
|
const resp = await this.client.hmset(key, pairs);
|
|
@@ -64,9 +73,8 @@ class Redis_ {
|
|
|
64
73
|
this.delete_hash = async (payload) => {
|
|
65
74
|
try {
|
|
66
75
|
const { key, field } = payload;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return resp;
|
|
76
|
+
await this.client.hdel(key, `${field}`);
|
|
77
|
+
return {};
|
|
70
78
|
}
|
|
71
79
|
catch (error) {
|
|
72
80
|
console.log(`[${this.className}-DELETE_HASH]`, error);
|
|
@@ -109,12 +117,28 @@ class Redis_ {
|
|
|
109
117
|
throw error;
|
|
110
118
|
}
|
|
111
119
|
};
|
|
112
|
-
this.
|
|
120
|
+
this.update_item = async (payload) => {
|
|
113
121
|
try {
|
|
114
|
-
const
|
|
122
|
+
const { key, value } = payload;
|
|
123
|
+
const keyData = await this.get_item(key);
|
|
124
|
+
if (!keyData)
|
|
125
|
+
throw { message: `${key} does not exisit` };
|
|
126
|
+
const updatedData = { ...keyData, value };
|
|
127
|
+
const resp = await this.client.set(key, JSON.stringify(updatedData));
|
|
115
128
|
return resp;
|
|
116
129
|
}
|
|
117
130
|
catch (error) {
|
|
131
|
+
console.log(`[${this.className}-SET_ITEM]`, error);
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
this.delete_item = async (key) => {
|
|
136
|
+
try {
|
|
137
|
+
await this.client.del(key);
|
|
138
|
+
return {};
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
console.log(`[${this.className}-DELETE_ITEM]`, error);
|
|
118
142
|
throw error;
|
|
119
143
|
}
|
|
120
144
|
};
|