@pi-r/redis 0.9.5 → 0.9.7

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.
Files changed (2) hide show
  1. package/client/index.js +15 -16
  2. package/package.json +3 -3
package/client/index.js CHANGED
@@ -149,9 +149,9 @@ async function executeBatchQuery(batch, options = '', outResult) {
149
149
  if (length === 0) {
150
150
  return [];
151
151
  }
152
- let parallel, checkObject, connectOnce, errorQuery, sessionKey, outCacheMiss;
152
+ let parallel, checkObject, connectOnce, errorQuery, errorAsEmpty, sessionKey, outCacheMiss;
153
153
  if ((0, types_1.isPlainObject)(options)) {
154
- ({ parallel, checkObject, connectOnce, errorQuery, sessionKey, outCacheMiss } = options);
154
+ ({ parallel, checkObject, connectOnce, errorQuery, errorAsEmpty, sessionKey, outCacheMiss } = options);
155
155
  }
156
156
  else {
157
157
  if (typeof options === 'string') {
@@ -204,7 +204,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
204
204
  }
205
205
  for (let i = 0; i < length; ++i) {
206
206
  const item = batch[i];
207
- const { source, uri, key, format = 'HASH', search, aggregate, update, options: clientOptions = {}, cacheObjectKey, ignoreCache } = item;
207
+ const { source, uri, key, search, aggregate, update, options: clientOptions = {}, ignoreCache } = item;
208
208
  let credential = (redisCredential || onceCredential), error;
209
209
  if (!credential && !(0, types_1.isPlainObject)(credential = clientOptions.client) && (error = (0, types_1.errorMessage)(source, "Invalid credentials")) || !((0, types_1.isString)(key) || (0, types_1.isArray)(key) || (0, types_1.isPlainObject)(search) && ((0, types_1.isPlainObject)(search.schema) || (0, types_1.isString)(search.query)) || (0, types_1.isPlainObject)(aggregate) && ((0, types_1.isPlainObject)(aggregate.schema) || (0, types_1.isString)(aggregate.query))) && (error = (0, types_1.errorMessage)(source, "Missing database query", uri))) {
210
210
  ++redisCache;
@@ -228,6 +228,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
228
228
  const uuidKey = credential.uuidKey ||= (onceCredential ? batch[0] : item).credential?.uuidKey;
229
229
  const targetObject = typeof checkObject === 'string' ? this.hasCoerce("redis", 'options', uuidKey) && (0, types_1.asFunction)(checkObject) : checkObject;
230
230
  const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
231
+ const format = (key ? item.format?.toUpperCase() || 'HASH' : undefined);
231
232
  let queryString = '', rows;
232
233
  if (caching && ignoreCache !== true) {
233
234
  if ((0, types_1.isObject)(search)) {
@@ -236,17 +237,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
236
237
  else if ((0, types_1.isObject)(aggregate)) {
237
238
  queryString = Db.asString(aggregate, true);
238
239
  }
239
- else if (!targetObject) {
240
- queryString = Db.asString(key, true);
241
- }
242
- else if (cacheObjectKey) {
243
- queryString = Db.asString(key, true) + '_' + targetObject.toString() + cacheObjectKey;
244
- }
245
- if (queryString) {
246
- queryString += '_' + format;
240
+ else if (key) {
241
+ queryString = Db.asString(key, true) + '_' + format;
242
+ if (targetObject && typeof item.cacheObjectKey === 'string') {
243
+ queryString += '_' + targetObject.toString() + item.cacheObjectKey;
244
+ }
247
245
  }
248
- if (ignoreCache !== 1) {
249
- if (rows = this.getQueryResult(source, DbPool.sanitize(credential), queryString, cacheValue)) {
246
+ if (ignoreCache !== 1 && !update) {
247
+ if (rows = this.getQueryResult(source, DbPool.sanitize(redisCredential || credential), queryString, cacheValue)) {
250
248
  ++redisCache;
251
249
  if (parallel) {
252
250
  tasks[i] = Promise.resolve(rows);
@@ -446,7 +444,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
446
444
  }
447
445
  if (pending) {
448
446
  pending.then(async (code) => {
449
- if (code === undefined || code === null || code !== -Infinity && (0, types_1.isString)(code) && code !== 'OK' || typeof code === 'number' && code <= codeMin || Array.isArray(code) && code.every(resp => resp === null || typeof resp === 'number' && resp <= codeMin)) {
447
+ if (code === undefined || code === null || (0, types_1.isString)(code) && code !== 'OK' && codeMin !== -Infinity || typeof code === 'number' && code <= codeMin || Array.isArray(code) && code.every(resp => resp === null || typeof resp === 'number' && resp <= codeMin)) {
450
448
  failValue();
451
449
  return;
452
450
  }
@@ -554,7 +552,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
554
552
  else if (key) {
555
553
  let data;
556
554
  if (Array.isArray(key)) {
557
- switch (format.toUpperCase()) {
555
+ switch (format) {
558
556
  case 'HKEYS':
559
557
  data = await Promise.all(key.map(async (k) => client.hKeys(...command ? [command, k] : [k])));
560
558
  break;
@@ -573,7 +571,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
573
571
  }
574
572
  }
575
573
  else {
576
- switch (format.toUpperCase()) {
574
+ switch (format) {
577
575
  case 'HKEYS':
578
576
  data = await client.hKeys(...command ? [command, key] : [key]);
579
577
  break;
@@ -637,6 +635,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
637
635
  }
638
636
  return this.processRows(batch, tasks, {
639
637
  parallel,
638
+ errorAsEmpty,
640
639
  disconnect() {
641
640
  for (const item of clients) {
642
641
  void item.disconnect();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/redis",
3
- "version": "0.9.5",
3
+ "version": "0.9.7",
4
4
  "description": "Redis client driver for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "types": "client/index.d.ts",
@@ -20,8 +20,8 @@
20
20
  "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/pi-r#readme",
22
22
  "dependencies": {
23
- "@e-mc/db": "^0.11.17",
24
- "@e-mc/types": "^0.11.17",
23
+ "@e-mc/db": "^0.11.19",
24
+ "@e-mc/types": "^0.11.19",
25
25
  "redis": "^4.7.0"
26
26
  }
27
27
  }