@pi-r/redis 0.12.0 → 0.12.1

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/client/index.js CHANGED
@@ -139,6 +139,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
139
139
  outResult ||= new Array(length);
140
140
  }
141
141
  const caching = this.hasCache("redis", sessionKey);
142
+ const sortKeys = this.settingsOf("redis", 'cache', 'sort_keys') === true;
142
143
  const tasks = new Array(length);
143
144
  const clients = [];
144
145
  const pools = [];
@@ -176,7 +177,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
176
177
  }
177
178
  for (let i = 0; i < length; ++i) {
178
179
  const item = batch[i];
179
- const { source, key, format = 'HASH', search, aggregate, streams, options: clientOptions = {}, ignoreCache } = item;
180
+ const { source, key, search, aggregate, streams, options: clientOptions = {}, ignoreCache } = item;
180
181
  let credential = redisCredential || onceCredential, error;
181
182
  if (!credential && !isPlainObject(credential = clientOptions.client) && (error = errorMessage(source, "Invalid credentials")) || !(isString(key) || isArray(key) || isPlainObject(search) && (isPlainObject(search.schema) || isString(search.query)) || isPlainObject(aggregate) && (isPlainObject(aggregate.schema) || isString(aggregate.query))) && (error = errorMessage(source, "Missing database query", item.uri))) {
182
183
  if (this.handleFail(error, item, { errorQuery })) {
@@ -198,7 +199,8 @@ async function executeBatchQuery(batch, options = '', outResult) {
198
199
  const uuidKey = credential.uuidKey ||= (onceCredential ? batch[0] : item).credential?.uuidKey;
199
200
  const targetObject = typeof checkObject === 'string' ? this.hasCoerce("redis", 'options', uuidKey) ? asFunction(checkObject) : null : checkObject;
200
201
  const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
201
- let queryString = '', rows;
202
+ const format = (key ? item.format?.toUpperCase() || 'HASH' : undefined);
203
+ let queryString = '', cacheCredential, rows;
202
204
  if (caching && ignoreCache !== true) {
203
205
  if (isObject(search)) {
204
206
  queryString = Db.asString(search, true);
@@ -209,17 +211,15 @@ async function executeBatchQuery(batch, options = '', outResult) {
209
211
  else if (streams) {
210
212
  queryString = Db.asString(streams, true);
211
213
  }
212
- else if (!targetObject) {
213
- queryString = Db.asString(key, true);
214
- }
215
- else if (item.cacheObjectKey) {
216
- queryString = Db.asString(key, true) + '_' + targetObject.toString() + item.cacheObjectKey;
217
- }
218
- if (queryString) {
219
- queryString += '_' + format;
214
+ else if (key) {
215
+ queryString = Db.asString(key, true) + '_' + format;
216
+ if (targetObject && typeof item.cacheObjectKey === 'string') {
217
+ queryString += '_' + targetObject.toString() + item.cacheObjectKey;
218
+ }
220
219
  }
220
+ cacheCredential = DbPool.sanitize(redisCredential || credential, sortKeys);
221
221
  if (ignoreCache !== 1) {
222
- rows = this.getQueryResult(source, DbPool.sanitize(credential), queryString, cacheValue);
222
+ rows = this.getQueryResult(source, cacheCredential, queryString, cacheValue);
223
223
  if (rows) {
224
224
  if (parallel) {
225
225
  tasks[i] = Promise.resolve(rows);
@@ -557,7 +557,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
557
557
  else if (key) {
558
558
  let data;
559
559
  if (Array.isArray(key)) {
560
- switch (format.toUpperCase()) {
560
+ switch (format) {
561
561
  case 'HKEYS':
562
562
  data = await Promise.all(key.map(async (k) => client.hKeys(k)));
563
563
  break;
@@ -579,7 +579,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
579
579
  }
580
580
  }
581
581
  else {
582
- switch (format.toUpperCase()) {
582
+ switch (format) {
583
583
  case 'HKEYS':
584
584
  data = await client.hKeys(key);
585
585
  break;
@@ -614,7 +614,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
614
614
  throw errorMessage(source, "Missing database query");
615
615
  }
616
616
  this.add(item, 4);
617
- resolve(this.setQueryResult(source, DbPool.sanitize(redisCredential || credential), queryString, rows, cacheValue));
617
+ resolve(this.setQueryResult(source, cacheCredential, queryString, rows, cacheValue));
618
618
  }
619
619
  catch (err) {
620
620
  switch (isError(err) && err.message) {
package/client/pool.js CHANGED
@@ -10,15 +10,21 @@ class RedisPool extends DbPool {
10
10
  }
11
11
  return super.asString(credential);
12
12
  }
13
- static sanitize(credential) {
13
+ static sanitize(credential, sort) {
14
14
  if (!this.canCache(credential)) {
15
15
  return;
16
16
  }
17
17
  if (!POOL_ACTIVE.has(credential) || credential.uuidKey) {
18
18
  return credential;
19
19
  }
20
+ if (sort) {
21
+ credential = super.sanitize(credential, true);
22
+ }
20
23
  if ('socket' in credential) {
21
- return { ...credential, socket: credential.socket?.tls ? { tls: true } : undefined };
24
+ if (!sort) {
25
+ credential = { ...credential };
26
+ }
27
+ credential.socket = credential.socket?.tls ? { tls: true } : undefined;
22
28
  }
23
29
  return credential;
24
30
  }
package/package.json CHANGED
@@ -1,12 +1,9 @@
1
1
  {
2
2
  "name": "@pi-r/redis",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "description": "Redis client driver for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "types": "client/index.d.ts",
7
- "publishConfig": {
8
- "access": "public"
9
- },
10
7
  "repository": {
11
8
  "type": "git",
12
9
  "url": "git+https://github.com/anpham6/pi-r2.git",
@@ -20,8 +17,8 @@
20
17
  "license": "MIT",
21
18
  "homepage": "https://github.com/anpham6/pi-r#readme",
22
19
  "dependencies": {
23
- "@e-mc/db": "^0.14.0",
24
- "@e-mc/types": "^0.14.0",
20
+ "@e-mc/db": "^0.14.1",
21
+ "@e-mc/types": "^0.14.1",
25
22
  "redis": "^5.12.1"
26
23
  }
27
24
  }