@pi-r/redis 0.8.5 → 0.8.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
@@ -147,9 +147,9 @@ async function executeBatchQuery(batch, options = '', outResult) {
147
147
  if (length === 0) {
148
148
  return [];
149
149
  }
150
- let parallel, checkObject, connectOnce, errorQuery, sessionKey, outCacheMiss;
150
+ let parallel, checkObject, connectOnce, errorQuery, errorAsEmpty, sessionKey, outCacheMiss;
151
151
  if ((0, types_1.isPlainObject)(options)) {
152
- ({ parallel, checkObject, connectOnce, errorQuery, sessionKey, outCacheMiss } = options);
152
+ ({ parallel, checkObject, connectOnce, errorQuery, errorAsEmpty, sessionKey, outCacheMiss } = options);
153
153
  }
154
154
  else {
155
155
  if (typeof options === 'string') {
@@ -202,7 +202,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
202
202
  }
203
203
  for (let i = 0; i < length; ++i) {
204
204
  const item = batch[i];
205
- const { source, uri, key, format = 'HASH', search, aggregate, update, options: clientOptions = {}, cacheObjectKey, ignoreCache } = item;
205
+ const { source, uri, key, search, aggregate, update, options: clientOptions = {}, ignoreCache } = item;
206
206
  let credential = (redisCredential || onceCredential), error;
207
207
  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))) {
208
208
  ++redisCache;
@@ -226,6 +226,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
226
226
  const uuidKey = (credential.uuidKey ||= (onceCredential ? batch[0] : item).credential?.uuidKey);
227
227
  const targetObject = typeof checkObject === 'string' ? this.hasCoerce("redis", 'options', uuidKey) && (0, types_1.asFunction)(checkObject) : checkObject;
228
228
  const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
229
+ const format = (key ? item.format?.toUpperCase() || 'HASH' : undefined);
229
230
  let queryString = '', rows;
230
231
  if (caching && ignoreCache !== true) {
231
232
  if ((0, types_1.isObject)(search)) {
@@ -234,17 +235,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
234
235
  else if ((0, types_1.isObject)(aggregate)) {
235
236
  queryString = Db.asString(aggregate, true);
236
237
  }
237
- else if (!targetObject) {
238
- queryString = Db.asString(key, true);
239
- }
240
- else if (cacheObjectKey) {
241
- queryString = Db.asString(key, true) + '_' + targetObject.toString() + cacheObjectKey;
242
- }
243
- if (queryString) {
244
- queryString += '_' + format;
238
+ else if (key) {
239
+ queryString = Db.asString(key, true) + '_' + format;
240
+ if (targetObject && typeof item.cacheObjectKey === 'string') {
241
+ queryString += '_' + targetObject.toString() + item.cacheObjectKey;
242
+ }
245
243
  }
246
- if (ignoreCache !== 1) {
247
- if (rows = this.getQueryResult(source, DbPool.sanitize(credential), queryString, cacheValue)) {
244
+ if (ignoreCache !== 1 && !update) {
245
+ if (rows = this.getQueryResult(source, DbPool.sanitize(redisCredential || credential), queryString, cacheValue)) {
248
246
  ++redisCache;
249
247
  if (parallel) {
250
248
  tasks[i] = Promise.resolve(rows);
@@ -444,7 +442,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
444
442
  }
445
443
  if (pending) {
446
444
  pending.then(async (code) => {
447
- 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)) {
445
+ 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)) {
448
446
  failValue();
449
447
  return;
450
448
  }
@@ -551,7 +549,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
551
549
  else if (key) {
552
550
  let data;
553
551
  if (Array.isArray(key)) {
554
- switch (format.toUpperCase()) {
552
+ switch (format) {
555
553
  case 'HKEYS':
556
554
  data = await Promise.all(key.map(async (k) => client.hKeys(...command ? [command, k] : [k])));
557
555
  break;
@@ -570,7 +568,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
570
568
  }
571
569
  }
572
570
  else {
573
- switch (format.toUpperCase()) {
571
+ switch (format) {
574
572
  case 'HKEYS':
575
573
  data = await client.hKeys(...command ? [command, key] : [key]);
576
574
  break;
@@ -634,6 +632,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
634
632
  }
635
633
  return this.processRows(batch, tasks, {
636
634
  parallel,
635
+ errorAsEmpty,
637
636
  disconnect() {
638
637
  for (const item of clients) {
639
638
  void item.disconnect();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/redis",
3
- "version": "0.8.5",
3
+ "version": "0.8.7",
4
4
  "description": "Redis client driver for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "types": "client/index.d.ts",
@@ -21,8 +21,8 @@
21
21
  "license": "MIT",
22
22
  "homepage": "https://github.com/anpham6/pi-r#readme",
23
23
  "dependencies": {
24
- "@e-mc/db": "^0.10.20",
25
- "@e-mc/types": "^0.10.20",
24
+ "@e-mc/db": "^0.10.22",
25
+ "@e-mc/types": "^0.10.22",
26
26
  "redis": "^4.7.0"
27
27
  }
28
28
  }