@pi-r/redis 0.9.3 → 0.10.0
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 +19 -20
- package/package.json +3 -3
- package/types/index.d.ts +4 -4
package/client/index.js
CHANGED
|
@@ -45,9 +45,7 @@ async function getClient(db, options, poolKey) {
|
|
|
45
45
|
.then(() => {
|
|
46
46
|
resolve(client);
|
|
47
47
|
})
|
|
48
|
-
.catch(
|
|
49
|
-
reject(err);
|
|
50
|
-
});
|
|
48
|
+
.catch(reject);
|
|
51
49
|
});
|
|
52
50
|
}
|
|
53
51
|
async function setCredential(item) {
|
|
@@ -71,7 +69,7 @@ async function setCredential(item) {
|
|
|
71
69
|
delete item.credential;
|
|
72
70
|
}
|
|
73
71
|
if (!uri) {
|
|
74
|
-
throw (0, types_1.errorMessage)("redis",
|
|
72
|
+
throw (0, types_1.errorMessage)("redis", "Invalid credentials", 'url');
|
|
75
73
|
}
|
|
76
74
|
if (client.socket?.tls) {
|
|
77
75
|
this.readTLSConfig(client.socket);
|
|
@@ -91,7 +89,8 @@ async function setCredential(item) {
|
|
|
91
89
|
username = undefined;
|
|
92
90
|
password = undefined;
|
|
93
91
|
if ((0, types_1.isString)(usePool)) {
|
|
94
|
-
|
|
92
|
+
username = client.username || (0, util_1.parseConnectionString)(uri)?.username;
|
|
93
|
+
if (username) {
|
|
95
94
|
[password, pool] = DbPool.validateKey(POOL_STATE, username, usePool);
|
|
96
95
|
if (pool) {
|
|
97
96
|
pool.add(item, password);
|
|
@@ -204,9 +203,9 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
204
203
|
}
|
|
205
204
|
for (let i = 0; i < length; ++i) {
|
|
206
205
|
const item = batch[i];
|
|
207
|
-
const { source,
|
|
206
|
+
const { source, key, format = 'HASH', search, aggregate, options: clientOptions = {}, ignoreCache } = item;
|
|
208
207
|
let credential = (redisCredential || onceCredential), error;
|
|
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))) {
|
|
208
|
+
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", item.uri))) {
|
|
210
209
|
++redisCache;
|
|
211
210
|
if (this.handleFail(error, item, { errorQuery })) {
|
|
212
211
|
if (!parallel) {
|
|
@@ -239,14 +238,15 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
239
238
|
else if (!targetObject) {
|
|
240
239
|
queryString = Db.asString(key, true);
|
|
241
240
|
}
|
|
242
|
-
else if (cacheObjectKey) {
|
|
243
|
-
queryString = Db.asString(key, true) + '_' + targetObject.toString() + cacheObjectKey;
|
|
241
|
+
else if (item.cacheObjectKey) {
|
|
242
|
+
queryString = Db.asString(key, true) + '_' + targetObject.toString() + item.cacheObjectKey;
|
|
244
243
|
}
|
|
245
244
|
if (queryString) {
|
|
246
245
|
queryString += '_' + format;
|
|
247
246
|
}
|
|
248
247
|
if (ignoreCache !== 1) {
|
|
249
|
-
|
|
248
|
+
rows = this.getQueryResult(source, DbPool.sanitize(credential), queryString, cacheValue);
|
|
249
|
+
if (rows) {
|
|
250
250
|
++redisCache;
|
|
251
251
|
if (parallel) {
|
|
252
252
|
tasks[i] = Promise.resolve(rows);
|
|
@@ -278,9 +278,9 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
278
278
|
const client = redisClient || await getConnection(item, credential);
|
|
279
279
|
const a = (arg) => typeof arg === 'string' || Buffer.isBuffer(arg) || typeof arg === 'number';
|
|
280
280
|
const b = (arg) => typeof arg === 'number' || Buffer.isBuffer(arg) ? arg.toString() : arg;
|
|
281
|
-
if (update) {
|
|
281
|
+
if (item.update) {
|
|
282
282
|
commandType = this.commandType.UPDATE;
|
|
283
|
-
const values = (!Array.isArray(update) ? [update] : update).map(async (target) => {
|
|
283
|
+
const values = (!Array.isArray(item.update) ? [item.update] : item.update).map(async (target) => {
|
|
284
284
|
return new Promise(async (success, failed) => {
|
|
285
285
|
let { key: k, value: v, format: f, NX, XX, options: setOptions = {} } = target;
|
|
286
286
|
f = ((0, types_1.isString)(f) ? f.toUpperCase() : 'HASH');
|
|
@@ -487,17 +487,13 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
487
487
|
failed((0, types_1.errorMessage)(f, "Invalid value", has(EX) ? 'EX: ' + EX : has(PX) ? 'PX: ' + PX : has(EXAT) ? 'EXAT: ' + EX : 'PXAT: ' + PXAT));
|
|
488
488
|
}
|
|
489
489
|
})
|
|
490
|
-
.catch(
|
|
491
|
-
failed(err);
|
|
492
|
-
});
|
|
490
|
+
.catch(failed);
|
|
493
491
|
}
|
|
494
492
|
else {
|
|
495
493
|
success(target);
|
|
496
494
|
}
|
|
497
495
|
})
|
|
498
|
-
.catch(
|
|
499
|
-
failed(err);
|
|
500
|
-
});
|
|
496
|
+
.catch(failed);
|
|
501
497
|
}
|
|
502
498
|
else {
|
|
503
499
|
failValue();
|
|
@@ -538,7 +534,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
538
534
|
}
|
|
539
535
|
}
|
|
540
536
|
catch (err) {
|
|
541
|
-
this.addLog(this.statusType.WARN, err,
|
|
537
|
+
this.addLog(this.statusType.WARN, err, { source: target === search ? 'FT.SEARCH' : 'FT.AGGREGATE' });
|
|
542
538
|
if (err instanceof Error) {
|
|
543
539
|
throw err;
|
|
544
540
|
}
|
|
@@ -587,7 +583,10 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
587
583
|
data = await (clientOptions.get ? client.json.get(...command ? [command, b(key), clientOptions.get] : [b(key), clientOptions.get]) : client.json.get(...command ? [command, b(key)] : [b(key)]));
|
|
588
584
|
break;
|
|
589
585
|
default:
|
|
590
|
-
if (item.field) {
|
|
586
|
+
if (Array.isArray(item.field)) {
|
|
587
|
+
data = await client.hmGet(...command ? [command, key, item.field] : [key, item.field]);
|
|
588
|
+
}
|
|
589
|
+
else if (item.field) {
|
|
591
590
|
data = await client.hGet(...command ? [command, key, item.field] : [key, item.field]);
|
|
592
591
|
}
|
|
593
592
|
else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/redis",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
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.
|
|
24
|
-
"@e-mc/types": "^0.
|
|
23
|
+
"@e-mc/db": "^0.12.0",
|
|
24
|
+
"@e-mc/types": "^0.12.0",
|
|
25
25
|
"redis": "^4.7.0"
|
|
26
26
|
}
|
|
27
27
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -4,20 +4,20 @@ import type { IdentifierAction } from '@e-mc/types/lib/core';
|
|
|
4
4
|
import type { CascadeAction, ServerAuth } from '@e-mc/types/lib/db';
|
|
5
5
|
import type { AuthValue } from '@e-mc/types/lib/http';
|
|
6
6
|
|
|
7
|
+
import type { RedisClientOptions } from '@redis/client';
|
|
8
|
+
import type { RedisJSON } from '@redis/json/dist/commands';
|
|
7
9
|
import type { ClientCommandOptions } from '@redis/client/dist/lib/client';
|
|
8
10
|
import type { RedisCommandArgument } from '@redis/client/dist/lib/commands';
|
|
9
11
|
import type { CommandOptions } from '@redis/client/dist/lib/command-options';
|
|
10
|
-
import type { RedisClientOptions } from '@redis/client';
|
|
11
|
-
import type { RedisJSON } from '@redis/json/dist/commands';
|
|
12
12
|
import type { AggregateOptions } from '@redis/search/dist/commands/AGGREGATE';
|
|
13
|
-
import type { HScanTuple } from '@redis
|
|
13
|
+
import type { HScanTuple } from '@redis/client/dist/lib/commands/HSCAN';
|
|
14
14
|
import type { ScanOptions } from '@redis/client/dist/lib/commands/generic-transformers';
|
|
15
15
|
import type { RediSearchSchema, SearchOptions, SetOptions } from 'redis';
|
|
16
16
|
|
|
17
17
|
export interface RedisDataSource extends DbDataSource<string, PlainObject, RedisSetValue | RedisSetValue[] | RedisJSONValue | RedisJSONValue[], RedisCredential, string>, CascadeAction, AuthValue {
|
|
18
18
|
source: "redis";
|
|
19
19
|
key?: RedisCommandArgument | RedisCommandArgument[];
|
|
20
|
-
field?: RedisCommandArgument;
|
|
20
|
+
field?: RedisCommandArgument | string[];
|
|
21
21
|
path?: string;
|
|
22
22
|
format?: RedisFormat | "HKEYS" | "HVALS" | "HSCAN";
|
|
23
23
|
search?: RedisQuery;
|