eip-cloud-services 1.0.7 → 1.0.8
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/package.json +1 -1
- package/src/redis.js +47 -11
package/package.json
CHANGED
package/src/redis.js
CHANGED
|
@@ -80,7 +80,43 @@ exports.get = async ( key ) => {
|
|
|
80
80
|
throw new Error ( `redis.get expects a string key, instead the type provided was: ${typeof key}` );
|
|
81
81
|
}
|
|
82
82
|
catch ( error ) {
|
|
83
|
-
console.log ( 'REDIS LIB ERROR [get]', error
|
|
83
|
+
console.log ( 'REDIS LIB ERROR [get]', error );
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Retrieves the values of multiple keys.
|
|
90
|
+
* @param {string[]} keys - The keys to retrieve.
|
|
91
|
+
* @returns {Promise} - A promise that resolves with the values of the keys.
|
|
92
|
+
*
|
|
93
|
+
* @description This method retrieves the values associated with the specified keys from Redis.
|
|
94
|
+
* If the value is a JSON string, it will be parsed and returned as a JavaScript object.
|
|
95
|
+
* If the value is not a valid JSON string, it will be returned as a string.
|
|
96
|
+
*/
|
|
97
|
+
exports.multiGet = async ( keys ) => {
|
|
98
|
+
try {
|
|
99
|
+
if ( Array.isArray ( keys ) ) {
|
|
100
|
+
const client = await getClient ();
|
|
101
|
+
|
|
102
|
+
const commandArgs = keys.map ( key => key.startsWith ( config.redis.prefix ) ? key : config.redis.prefix + key );
|
|
103
|
+
|
|
104
|
+
const data = await client.sendCommand ( [ 'MGET', ...commandArgs ] );
|
|
105
|
+
|
|
106
|
+
return data.map ( val => {
|
|
107
|
+
try {
|
|
108
|
+
return JSON.parse ( val );
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return val;
|
|
112
|
+
}
|
|
113
|
+
} );
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
throw new Error ( `redis.multiGet expects an array of keys, instead the type provided was: ${typeof keys}` );
|
|
117
|
+
}
|
|
118
|
+
catch ( error ) {
|
|
119
|
+
console.log ( 'REDIS LIB ERROR [multiGet]', error );
|
|
84
120
|
throw error;
|
|
85
121
|
}
|
|
86
122
|
};
|
|
@@ -145,7 +181,7 @@ exports.del = async ( key ) => {
|
|
|
145
181
|
throw new Error ( `redis.del expects a string key, instead the type provided was: ${typeof key}` );
|
|
146
182
|
}
|
|
147
183
|
catch ( error ) {
|
|
148
|
-
console.log ( 'REDIS LIB ERROR [del]', error
|
|
184
|
+
console.log ( 'REDIS LIB ERROR [del]', error );
|
|
149
185
|
throw error;
|
|
150
186
|
}
|
|
151
187
|
};
|
|
@@ -208,7 +244,7 @@ exports.setRemove = async ( key, members ) => {
|
|
|
208
244
|
throw new Error ( `redis.setRemove expects a string key, instead the type provided was: ${typeof key}` );
|
|
209
245
|
}
|
|
210
246
|
catch ( error ) {
|
|
211
|
-
console.log ( 'REDIS LIB ERROR [setRemove]', error
|
|
247
|
+
console.log ( 'REDIS LIB ERROR [setRemove]', error );
|
|
212
248
|
throw error;
|
|
213
249
|
}
|
|
214
250
|
};
|
|
@@ -236,7 +272,7 @@ exports.setMembers = async ( key ) => {
|
|
|
236
272
|
throw new Error ( `redis.setMembers expects a string key, instead the type provided was: ${typeof key}` );
|
|
237
273
|
}
|
|
238
274
|
catch ( error ) {
|
|
239
|
-
console.log ( 'REDIS LIB ERROR [setMembers]', error
|
|
275
|
+
console.log ( 'REDIS LIB ERROR [setMembers]', error );
|
|
240
276
|
throw error;
|
|
241
277
|
}
|
|
242
278
|
};
|
|
@@ -274,7 +310,7 @@ exports.setPop = async ( key ) => {
|
|
|
274
310
|
throw new Error ( `redis.setPop expects a string key, instead the type provided was: ${typeof key}` );
|
|
275
311
|
}
|
|
276
312
|
catch ( error ) {
|
|
277
|
-
console.log ( 'REDIS LIB ERROR [setPop]', error
|
|
313
|
+
console.log ( 'REDIS LIB ERROR [setPop]', error );
|
|
278
314
|
throw error;
|
|
279
315
|
}
|
|
280
316
|
};
|
|
@@ -315,7 +351,7 @@ exports.listUnshift = async ( key, values ) => {
|
|
|
315
351
|
throw new Error ( `redis.listUnshift expects a string key, instead the type provided was: ${typeof key}` );
|
|
316
352
|
}
|
|
317
353
|
catch ( error ) {
|
|
318
|
-
console.log ( 'REDIS LIB ERROR [listUnshift]', error
|
|
354
|
+
console.log ( 'REDIS LIB ERROR [listUnshift]', error );
|
|
319
355
|
throw error;
|
|
320
356
|
}
|
|
321
357
|
};
|
|
@@ -356,7 +392,7 @@ exports.listPush = async ( key, values ) => {
|
|
|
356
392
|
throw new Error ( `redis.listPush expects a string key, instead the type provided was: ${typeof key}` );
|
|
357
393
|
}
|
|
358
394
|
catch ( error ) {
|
|
359
|
-
console.log ( 'REDIS LIB ERROR [listPush]', error
|
|
395
|
+
console.log ( 'REDIS LIB ERROR [listPush]', error );
|
|
360
396
|
throw error;
|
|
361
397
|
}
|
|
362
398
|
};
|
|
@@ -388,7 +424,7 @@ exports.listPop = async ( key, count = 1 ) => {
|
|
|
388
424
|
throw new Error ( `redis.listPop expects a string key, instead the type provided was: ${typeof key}` );
|
|
389
425
|
}
|
|
390
426
|
catch ( error ) {
|
|
391
|
-
console.log ( 'REDIS LIB ERROR [listPop]', error
|
|
427
|
+
console.log ( 'REDIS LIB ERROR [listPop]', error );
|
|
392
428
|
throw error;
|
|
393
429
|
}
|
|
394
430
|
};
|
|
@@ -422,7 +458,7 @@ exports.listRange = async ( key, start = 0, end = -1 ) => {
|
|
|
422
458
|
throw new Error ( `redis.listRange expects a string key, instead the type provided was: ${typeof key}` );
|
|
423
459
|
}
|
|
424
460
|
catch ( error ) {
|
|
425
|
-
console.log ( 'REDIS LIB ERROR [listRange]', error
|
|
461
|
+
console.log ( 'REDIS LIB ERROR [listRange]', error );
|
|
426
462
|
throw error;
|
|
427
463
|
}
|
|
428
464
|
};
|
|
@@ -452,7 +488,7 @@ exports.getExpiryInSeconds = async ( key ) => {
|
|
|
452
488
|
throw new Error ( `redis.getExpiryInSeconds expects a string key, instead the type provided was: ${typeof key}` );
|
|
453
489
|
}
|
|
454
490
|
catch ( error ) {
|
|
455
|
-
console.log ( 'REDIS LIB ERROR [getExpiryInSeconds]', error
|
|
491
|
+
console.log ( 'REDIS LIB ERROR [getExpiryInSeconds]', error );
|
|
456
492
|
throw error;
|
|
457
493
|
}
|
|
458
494
|
};
|
|
@@ -483,7 +519,7 @@ exports.setExpiry = async ( key, seconds = 0 ) => {
|
|
|
483
519
|
throw new Error ( `redis.setExpiry expects a string key, instead the type provided was: ${typeof key}` );
|
|
484
520
|
}
|
|
485
521
|
catch ( error ) {
|
|
486
|
-
console.log ( 'REDIS LIB ERROR [setExpiry]', error
|
|
522
|
+
console.log ( 'REDIS LIB ERROR [setExpiry]', error );
|
|
487
523
|
throw error;
|
|
488
524
|
}
|
|
489
525
|
};
|