@pi-r/redis 0.11.3 → 0.11.4
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 +14 -18
- package/package.json +3 -3
package/client/index.js
CHANGED
|
@@ -116,9 +116,9 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
116
116
|
if (length === 0) {
|
|
117
117
|
return [];
|
|
118
118
|
}
|
|
119
|
-
let parallel, checkObject, connectOnce, errorQuery, sessionKey, outCacheMiss;
|
|
119
|
+
let parallel, checkObject, connectOnce, errorQuery, errorAsEmpty, sessionKey, outCacheMiss;
|
|
120
120
|
if (types.isPlainObject(options)) {
|
|
121
|
-
({ parallel, checkObject, connectOnce, errorQuery, sessionKey, outCacheMiss } = options);
|
|
121
|
+
({ parallel, checkObject, connectOnce, errorQuery, errorAsEmpty, sessionKey, outCacheMiss } = options);
|
|
122
122
|
}
|
|
123
123
|
else {
|
|
124
124
|
if (typeof options === 'string') {
|
|
@@ -174,9 +174,9 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
174
174
|
}
|
|
175
175
|
for (let i = 0; i < length; ++i) {
|
|
176
176
|
const item = batch[i];
|
|
177
|
-
const { source, key,
|
|
177
|
+
const { source, key, search, aggregate, streams, options: clientOptions = {}, ignoreCache } = item;
|
|
178
178
|
let credential = (redisCredential || onceCredential), error;
|
|
179
|
-
if (!credential && !types.isPlainObject(credential = clientOptions.client) && (error = types.errorMessage(source, "Invalid credentials")) || !(types.isString(key) || types.isArray(key) || types.isPlainObject(search) && (types.isPlainObject(search.schema) || types.isString(search.query)) || types.isPlainObject(aggregate) && (types.isPlainObject(aggregate.schema) || types.isString(aggregate.query))) && (error = types.errorMessage(source, "Missing database query", item.uri))) {
|
|
179
|
+
if (!credential && !types.isPlainObject(credential = clientOptions.client) && (error = types.errorMessage(source, "Invalid credentials")) || !(types.isString(key) || types.isArray(key) || streams || types.isPlainObject(search) && (types.isPlainObject(search.schema) || types.isString(search.query)) || types.isPlainObject(aggregate) && (types.isPlainObject(aggregate.schema) || types.isString(aggregate.query))) && (error = types.errorMessage(source, "Missing database query", item.uri))) {
|
|
180
180
|
if (this.handleFail(error, item, { errorQuery })) {
|
|
181
181
|
if (!parallel) {
|
|
182
182
|
tasks.length = 0;
|
|
@@ -196,6 +196,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
196
196
|
const uuidKey = credential.uuidKey ||= (onceCredential ? batch[0] : item).credential?.uuidKey;
|
|
197
197
|
const targetObject = typeof checkObject === 'string' ? this.hasCoerce("redis", 'options', uuidKey) && types.asFunction(checkObject) : checkObject;
|
|
198
198
|
const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
|
|
199
|
+
const format = (key ? item.format?.toUpperCase() || 'HASH' : undefined);
|
|
199
200
|
let queryString = '', rows;
|
|
200
201
|
if (caching && ignoreCache !== true) {
|
|
201
202
|
if (types.isObject(search)) {
|
|
@@ -207,14 +208,11 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
207
208
|
else if (streams) {
|
|
208
209
|
queryString = Db.asString(streams, true);
|
|
209
210
|
}
|
|
210
|
-
else if (
|
|
211
|
-
queryString = Db.asString(key, true);
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
if (queryString) {
|
|
217
|
-
queryString += '_' + format;
|
|
211
|
+
else if (key) {
|
|
212
|
+
queryString = Db.asString(key, true) + '_' + format;
|
|
213
|
+
if (targetObject && typeof item.cacheObjectKey === 'string') {
|
|
214
|
+
queryString += '_' + targetObject.toString() + item.cacheObjectKey;
|
|
215
|
+
}
|
|
218
216
|
}
|
|
219
217
|
if (ignoreCache !== 1) {
|
|
220
218
|
rows = this.getQueryResult(source, DbPool.sanitize(credential), queryString, cacheValue);
|
|
@@ -537,15 +535,12 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
537
535
|
}
|
|
538
536
|
}
|
|
539
537
|
else if (streams) {
|
|
540
|
-
|
|
541
|
-
if (data) {
|
|
542
|
-
rows = data;
|
|
543
|
-
}
|
|
538
|
+
rows = await client.xRead(streams, clientOptions.xread);
|
|
544
539
|
}
|
|
545
540
|
else if (key) {
|
|
546
541
|
let data;
|
|
547
542
|
if (Array.isArray(key)) {
|
|
548
|
-
switch (format
|
|
543
|
+
switch (format) {
|
|
549
544
|
case 'HKEYS':
|
|
550
545
|
data = await Promise.all(key.map(async (k) => client.hKeys(k)));
|
|
551
546
|
break;
|
|
@@ -567,7 +562,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
567
562
|
}
|
|
568
563
|
}
|
|
569
564
|
else {
|
|
570
|
-
switch (format
|
|
565
|
+
switch (format) {
|
|
571
566
|
case 'HKEYS':
|
|
572
567
|
data = await client.hKeys(key);
|
|
573
568
|
break;
|
|
@@ -637,6 +632,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
637
632
|
}
|
|
638
633
|
return this.processRows(batch, tasks, {
|
|
639
634
|
parallel,
|
|
635
|
+
errorAsEmpty,
|
|
640
636
|
disconnect() {
|
|
641
637
|
for (const item of clients) {
|
|
642
638
|
item.destroy();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/redis",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.4",
|
|
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.13.
|
|
24
|
-
"@e-mc/types": "^0.13.
|
|
23
|
+
"@e-mc/db": "^0.13.12",
|
|
24
|
+
"@e-mc/types": "^0.13.12",
|
|
25
25
|
"redis": "^5.12.1"
|
|
26
26
|
}
|
|
27
27
|
}
|