@pi-r/redis 0.6.4 → 0.6.6
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/LICENSE +1 -1
- package/README.md +6 -3
- package/client/index.js +20 -21
- package/package.json +3 -3
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
package/README.md
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
# @pi-r/redis
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Documentation
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
- [E-mc](https://e-mc.readthedocs.io/en/latest/db/redis.html)
|
|
6
|
+
- [squared](https://squared.readthedocs.io)
|
|
7
|
+
|
|
8
|
+
## LICENSE
|
|
6
9
|
|
|
7
10
|
MIT
|
package/client/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
2
|
exports.DB_SOURCE_TYPE = exports.DB_SOURCE_CLIENT = exports.checkTimeout = exports.executeBatchQuery = exports.executeQuery = exports.setCredential = void 0;
|
|
4
3
|
const redis = require("redis");
|
|
5
4
|
const util_1 = require("@e-mc/db/util");
|
|
@@ -56,7 +55,7 @@ async function setCredential(item) {
|
|
|
56
55
|
client.database = database;
|
|
57
56
|
}
|
|
58
57
|
if (credential) {
|
|
59
|
-
const auth = (0, util_1.parseServerAuth)(credential, 6379
|
|
58
|
+
const auth = (0, util_1.parseServerAuth)(credential, 6379);
|
|
60
59
|
if (!client.database) {
|
|
61
60
|
if ('database' in credential) {
|
|
62
61
|
const value = credential.database;
|
|
@@ -69,7 +68,7 @@ async function setCredential(item) {
|
|
|
69
68
|
client.database = database;
|
|
70
69
|
}
|
|
71
70
|
}
|
|
72
|
-
uri || (uri = (auth.protocol || 'redis:') + '//' + (auth.server || 'localhost:' + (auth.port ? auth.port : 6379
|
|
71
|
+
uri || (uri = (auth.protocol || 'redis:') + '//' + (auth.server || 'localhost:' + (auth.port ? auth.port : 6379)));
|
|
73
72
|
username || (username = auth.username);
|
|
74
73
|
password || (password = auth.password);
|
|
75
74
|
}
|
|
@@ -77,7 +76,7 @@ async function setCredential(item) {
|
|
|
77
76
|
delete item.credential;
|
|
78
77
|
}
|
|
79
78
|
if (!uri) {
|
|
80
|
-
throw (0, types_1.errorMessage)("redis"
|
|
79
|
+
throw (0, types_1.errorMessage)("redis", 'Not defined - uri');
|
|
81
80
|
}
|
|
82
81
|
if (client.socket?.tls) {
|
|
83
82
|
this.readTLSConfig(client.socket);
|
|
@@ -109,7 +108,7 @@ async function setCredential(item) {
|
|
|
109
108
|
return;
|
|
110
109
|
}
|
|
111
110
|
}
|
|
112
|
-
const config = this.getPoolConfig("redis"
|
|
111
|
+
const config = this.getPoolConfig("redis", password);
|
|
113
112
|
const poolOptions = client.isolationPoolOptions || (client.isolationPoolOptions = {});
|
|
114
113
|
if (config) {
|
|
115
114
|
const { min, max, idle, queue_max, queue_idle, timeout } = config;
|
|
@@ -177,12 +176,12 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
177
176
|
if (!parallel) {
|
|
178
177
|
outResult || (outResult = new Array(length));
|
|
179
178
|
}
|
|
180
|
-
const caching = this.hasCache("redis"
|
|
179
|
+
const caching = this.hasCache("redis", sessionKey);
|
|
181
180
|
const tasks = new Array(length);
|
|
182
181
|
const clients = [];
|
|
183
182
|
let redisClient, redisCredential, redisCache = 0, onceCredential = connectOnce ? batch[0].options?.client : undefined;
|
|
184
183
|
const getConnection = async (item, credential) => {
|
|
185
|
-
item.transactionState = 64
|
|
184
|
+
item.transactionState = 64;
|
|
186
185
|
let client;
|
|
187
186
|
if (item.usePool) {
|
|
188
187
|
const pool = DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(credential), ...connectOnce ? [item, batch[0]] : [item]);
|
|
@@ -205,7 +204,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
205
204
|
redisClient = client;
|
|
206
205
|
redisCredential = credential;
|
|
207
206
|
}
|
|
208
|
-
item.transactionState &= ~64
|
|
207
|
+
item.transactionState &= ~64;
|
|
209
208
|
return client;
|
|
210
209
|
};
|
|
211
210
|
if (this.host?.username) {
|
|
@@ -215,7 +214,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
215
214
|
const item = batch[i];
|
|
216
215
|
const { source, uri, key, format = 'HASH', search, aggregate, update, options: clientOptions = {}, cacheObjectKey, ignoreCache } = item;
|
|
217
216
|
let credential = (redisCredential || onceCredential), error;
|
|
218
|
-
if (!credential && !(0, types_1.isPlainObject)(credential = clientOptions.client) && (error = (0, types_1.errorMessage)(source, "Invalid credentials"
|
|
217
|
+
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))) {
|
|
219
218
|
++redisCache;
|
|
220
219
|
if (this.handleFail(error, item, { errorQuery })) {
|
|
221
220
|
if (!parallel) {
|
|
@@ -232,10 +231,10 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
232
231
|
}
|
|
233
232
|
continue;
|
|
234
233
|
}
|
|
235
|
-
item.transactionState = 1
|
|
234
|
+
item.transactionState = 1;
|
|
236
235
|
const command = (0, types_1.isPlainObject)(clientOptions.command) ? redis.commandOptions(clientOptions.command) : null;
|
|
237
236
|
const uuidKey = (credential.uuidKey || (credential.uuidKey = (onceCredential ? batch[0] : item).credential?.uuidKey));
|
|
238
|
-
const targetObject = typeof checkObject === 'string' ? this.hasCoerce("redis"
|
|
237
|
+
const targetObject = typeof checkObject === 'string' ? this.hasCoerce("redis", 'options', uuidKey) && (0, types_1.asFunction)(checkObject) : checkObject;
|
|
239
238
|
const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
|
|
240
239
|
let queryString = '', rows;
|
|
241
240
|
if (caching && ignoreCache !== true) {
|
|
@@ -263,7 +262,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
263
262
|
else {
|
|
264
263
|
outResult[i] = rows;
|
|
265
264
|
}
|
|
266
|
-
this.add(item, 4
|
|
265
|
+
this.add(item, 4 | 128);
|
|
267
266
|
continue;
|
|
268
267
|
}
|
|
269
268
|
if (!ignoreCache && outCacheMiss) {
|
|
@@ -298,8 +297,8 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
298
297
|
return;
|
|
299
298
|
}
|
|
300
299
|
const has = (n) => typeof n === 'number' && n > 0;
|
|
301
|
-
const failKey = () => failed((0, types_1.errorMessage)(f, "Invalid key"
|
|
302
|
-
const failValue = () => failed((0, types_1.errorMessage)(f, "Invalid value"
|
|
300
|
+
const failKey = () => failed((0, types_1.errorMessage)(f, "Invalid key", Db.asString(k) || "Unknown"));
|
|
301
|
+
const failValue = () => failed((0, types_1.errorMessage)(f, "Invalid value", Db.asString(v) || "Unknown"));
|
|
303
302
|
const commandSet = (0, types_1.isPlainObject)(setOptions.command) && redis.commandOptions(setOptions.command);
|
|
304
303
|
let pending, codeMin = 0, EX, PX, EXAT, PXAT, KEEPTTL;
|
|
305
304
|
if (f === 'JSON') {
|
|
@@ -307,7 +306,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
307
306
|
failKey();
|
|
308
307
|
return;
|
|
309
308
|
}
|
|
310
|
-
if (this.hasCoerce("redis"
|
|
309
|
+
if (this.hasCoerce("redis", 'options', uuidKey)) {
|
|
311
310
|
if ((0, types_1.isString)(v) && v.startsWith('new')) {
|
|
312
311
|
({ outV: v } = (0, types_1.coerceObject)({ outV: v }));
|
|
313
312
|
}
|
|
@@ -491,7 +490,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
491
490
|
success(target);
|
|
492
491
|
}
|
|
493
492
|
else {
|
|
494
|
-
failed((0, types_1.errorMessage)(f, "Invalid value"
|
|
493
|
+
failed((0, types_1.errorMessage)(f, "Invalid value", has(EX) ? 'EX: ' + EX : has(PX) ? 'PX: ' + PX : has(EXAT) ? 'EXAT: ' + EX : 'PXAT: ' + PXAT));
|
|
495
494
|
}
|
|
496
495
|
})
|
|
497
496
|
.catch(err => failed(err));
|
|
@@ -547,7 +546,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
547
546
|
}
|
|
548
547
|
finally {
|
|
549
548
|
if (idx && idx !== index) {
|
|
550
|
-
client.ft.dropIndex(idx).catch(err => this.writeFail([`Unable to drop ${target === search ? 'search' : 'aggregate'} index`, idx], err, { type: 65536
|
|
549
|
+
client.ft.dropIndex(idx).catch(err => this.writeFail([`Unable to drop ${target === search ? 'search' : 'aggregate'} index`, idx], err, { type: 65536, fatal: false }));
|
|
551
550
|
}
|
|
552
551
|
}
|
|
553
552
|
}
|
|
@@ -593,16 +592,16 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
593
592
|
rows = (targetObject ? targetObject(item, data) : data);
|
|
594
593
|
}
|
|
595
594
|
if (rows === undefined) {
|
|
596
|
-
throw (0, types_1.errorMessage)(source, "Missing database query"
|
|
595
|
+
throw (0, types_1.errorMessage)(source, "Missing database query");
|
|
597
596
|
}
|
|
598
|
-
this.add(item, 4
|
|
597
|
+
this.add(item, 4);
|
|
599
598
|
resolve(this.setQueryResult(source, removePoolProperties(redisCredential || credential), queryString, rows, cacheValue));
|
|
600
599
|
}
|
|
601
600
|
catch (err) {
|
|
602
601
|
if (err instanceof Error) {
|
|
603
602
|
switch (err.message) {
|
|
604
|
-
case "The client is closed"
|
|
605
|
-
case "Disconnects client"
|
|
603
|
+
case "The client is closed":
|
|
604
|
+
case "Disconnects client": {
|
|
606
605
|
const pool = item.usePool && DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(credential));
|
|
607
606
|
if (pool) {
|
|
608
607
|
await pool.detach(true);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/redis",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
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.8.
|
|
25
|
-
"@e-mc/types": "^0.8.
|
|
24
|
+
"@e-mc/db": "^0.8.7",
|
|
25
|
+
"@e-mc/types": "^0.8.7",
|
|
26
26
|
"redis": "^4.6.13"
|
|
27
27
|
}
|
|
28
28
|
}
|