eip-cloud-services 1.1.11 → 1.1.13
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/mysql.js +10 -3
- package/src/redis.js +19 -13
package/package.json
CHANGED
package/src/mysql.js
CHANGED
|
@@ -27,9 +27,16 @@ const newQuery = ( connection, query ) => new Promise ( ( resolve, reject ) => {
|
|
|
27
27
|
connection.query ( query, ( error, results, fields ) => {
|
|
28
28
|
connection.release ();
|
|
29
29
|
if ( error ) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
const MAX_ERROR_LENGTH = 500;
|
|
31
|
+
const MAX_QUERY_LENGTH = 300;
|
|
32
|
+
|
|
33
|
+
const shortError = (error?.stack || error?.message || String(error)).slice(0, MAX_ERROR_LENGTH);
|
|
34
|
+
const shortQuery = query.slice(0, MAX_QUERY_LENGTH);
|
|
35
|
+
|
|
36
|
+
console.error("Query Error:", shortError);
|
|
37
|
+
console.error("Truncated Query:", shortQuery);
|
|
38
|
+
|
|
39
|
+
reject(`There was a problem with query: ${shortError}`);
|
|
33
40
|
}
|
|
34
41
|
else {
|
|
35
42
|
resolve ( results );
|
package/src/redis.js
CHANGED
|
@@ -248,26 +248,32 @@ exports.multiGet = async ( keys ) => {
|
|
|
248
248
|
* @param {*} value - The value to set for the key.
|
|
249
249
|
* @param {string} [ex] - Optional EX parameter to set expiration in seconds.
|
|
250
250
|
* @param {number} [px] - Optional PX parameter to set expiration in milliseconds.
|
|
251
|
+
* @param {boolean}[nx] – NX flag → “only set if key does not exist”
|
|
251
252
|
* @returns {Promise} - A promise that resolves with the result of the SET command.
|
|
252
253
|
*
|
|
253
254
|
* @description This method sets the value for the specified key in Redis.
|
|
254
255
|
* If the value is an object or array, it will be automatically converted to a JSON string before storing.
|
|
255
256
|
* Optionally, you can set an expiration time for the key using the `ex` parameter in seconds or the `px` parameter in milliseconds.
|
|
256
257
|
*/
|
|
257
|
-
exports.set = async ( key, value, ex, px ) => {
|
|
258
|
+
exports.set = async ( key, value, ex, px, nx ) => {
|
|
258
259
|
try {
|
|
259
|
-
if (
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
260
|
+
if (typeof key !== 'string')
|
|
261
|
+
throw new Error(`redis.set expects a string key, got ${typeof key}`);
|
|
262
|
+
|
|
263
|
+
const client = await getClient();
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
const fullKey = (!config?.redis?.prefix || key.startsWith(config.redis.prefix)) ? key : config.redis.prefix + key;
|
|
267
|
+
const serialised = (typeof value === 'object' && value !== null) ? JSON.stringify(value) : value;
|
|
268
|
+
|
|
269
|
+
const args = [];
|
|
270
|
+
if (nx) args.push('NX');
|
|
271
|
+
if (ex !== undefined && px !== undefined)
|
|
272
|
+
throw new Error('redis.set: cannot specify both EX and PX');
|
|
273
|
+
if (ex !== undefined) args.push('EX', ex);
|
|
274
|
+
if (px !== undefined) args.push('PX', px);
|
|
275
|
+
|
|
276
|
+
return await client.set(fullKey, serialised, ...args);
|
|
271
277
|
}
|
|
272
278
|
catch ( error ) {
|
|
273
279
|
console.log ( 'REDIS LIB ERROR [set]', error );
|