@pi-r/redis 0.6.1 → 0.6.3
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/README.md +2 -0
- package/client/index.js +16 -14
- package/package.json +4 -4
- package/types/index.d.ts +5 -5
package/README.md
CHANGED
package/client/index.js
CHANGED
|
@@ -6,7 +6,6 @@ const util_1 = require("@e-mc/db/util");
|
|
|
6
6
|
const types_1 = require("@e-mc/types");
|
|
7
7
|
const Db = require("@e-mc/db");
|
|
8
8
|
const DbPool = require('@e-mc/db/pool');
|
|
9
|
-
const REDIS_V4 = Db.checkSemVer("redis" /* STRINGS.MODULE_NAME */, 4);
|
|
10
9
|
class RedisPool extends DbPool {
|
|
11
10
|
async getConnection() {
|
|
12
11
|
return this.client;
|
|
@@ -46,11 +45,8 @@ function removePoolProperties(options) {
|
|
|
46
45
|
}
|
|
47
46
|
return options;
|
|
48
47
|
}
|
|
49
|
-
const getPoolKey = (options) => options.url
|
|
48
|
+
const getPoolKey = (options) => options.url && JSON.stringify(options);
|
|
50
49
|
async function setCredential(item) {
|
|
51
|
-
if (!REDIS_V4) {
|
|
52
|
-
throw (0, types_1.errorValue)("Upgrade client to latest version" /* ERR_DB.UPGRADE */, "redis" /* STRINGS.MODULE_NAME */ + '@' + Db.getPackageVersion("redis" /* STRINGS.MODULE_NAME */));
|
|
53
|
-
}
|
|
54
50
|
const credential = this.getCredential(item);
|
|
55
51
|
const options = item.options || (item.options = {});
|
|
56
52
|
const client = (0, types_1.isPlainObject)(options.client) ? options.client : options.client = {};
|
|
@@ -99,18 +95,19 @@ async function setCredential(item) {
|
|
|
99
95
|
let pool;
|
|
100
96
|
username = undefined;
|
|
101
97
|
password = undefined;
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
pool
|
|
98
|
+
if ((0, types_1.isString)(usePool)) {
|
|
99
|
+
if (username = client.username || (0, util_1.parseConnectionString)(uri)?.username) {
|
|
100
|
+
[password, pool] = DbPool.validateKey(POOL_STATE, username, usePool);
|
|
101
|
+
if (pool) {
|
|
102
|
+
pool.add(item, password);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (!password) {
|
|
107
|
+
item.usePool = '';
|
|
106
108
|
return;
|
|
107
109
|
}
|
|
108
110
|
}
|
|
109
|
-
const poolKey = getPoolKey(client);
|
|
110
|
-
if ((pool = POOL_STATE[poolKey]) && !pool.closed) {
|
|
111
|
-
pool.add(item);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
111
|
const config = this.getPoolConfig("redis" /* STRINGS.MODULE_NAME */, password);
|
|
115
112
|
const poolOptions = client.isolationPoolOptions || (client.isolationPoolOptions = {});
|
|
116
113
|
if (config) {
|
|
@@ -134,6 +131,11 @@ async function setCredential(item) {
|
|
|
134
131
|
poolOptions.acquireTimeoutMillis ?? (poolOptions.acquireTimeoutMillis = timeout);
|
|
135
132
|
}
|
|
136
133
|
}
|
|
134
|
+
const poolKey = getPoolKey(client);
|
|
135
|
+
if ((pool = POOL_STATE[poolKey]) && !pool.closed) {
|
|
136
|
+
pool.add(item);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
137
139
|
try {
|
|
138
140
|
const target = new RedisPool(await getClient(redis, client, poolKey), poolKey, username && password ? { username, password } : undefined).add(item);
|
|
139
141
|
target.parent = POOL_STATE;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/redis",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"description": "Redis client driver for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"types": "client/index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/anpham6/pi-r.git",
|
|
12
|
+
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
13
13
|
"directory": "src/db/redis"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
@@ -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.3",
|
|
25
|
+
"@e-mc/types": "^0.8.3",
|
|
26
26
|
"redis": "^4.6.12"
|
|
27
27
|
}
|
|
28
28
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { DbDataSource } from '@e-mc/types/lib/squared';
|
|
2
2
|
|
|
3
|
-
import type { CascadeAction,
|
|
3
|
+
import type { CascadeAction, ServerAuth } from '@e-mc/types/lib/db';
|
|
4
4
|
|
|
5
5
|
import type { CommandOptions } from '@redis/client/dist/lib/command-options';
|
|
6
|
-
import type { ClientCommandOptions
|
|
6
|
+
import type { ClientCommandOptions } from '@redis/client/dist/lib/client';
|
|
7
7
|
import type { RedisClientOptions } from '@redis/client';
|
|
8
8
|
import type { RedisCommandArgument } from '@redis/client/dist/lib/commands';
|
|
9
9
|
import type { RedisJSON } from '@redis/json/dist/commands';
|
|
10
|
-
import type {
|
|
10
|
+
import type { RediSearchSchema, SearchOptions, SetOptions } from 'redis';
|
|
11
11
|
|
|
12
|
-
export interface RedisDataSource extends DbDataSource<string, PlainObject, ArrayOf<RedisSetValue> | ArrayOf<RedisJSONValue>, string | RedisCredential, string>,
|
|
12
|
+
export interface RedisDataSource extends DbDataSource<string, PlainObject, ArrayOf<RedisSetValue> | ArrayOf<RedisJSONValue>, string | RedisCredential, string>, AuthValue, CascadeAction {
|
|
13
13
|
source: "redis";
|
|
14
14
|
key?: ArrayOf<RedisCommandArgument>;
|
|
15
15
|
field?: RedisCommandArgument;
|
|
@@ -22,7 +22,7 @@ export interface RedisDataSource extends DbDataSource<string, PlainObject, Array
|
|
|
22
22
|
command?: RedisCommandOptions;
|
|
23
23
|
get?: PlainObject;
|
|
24
24
|
search?: SearchOptions;
|
|
25
|
-
aggregate?:
|
|
25
|
+
aggregate?: PlainObject;
|
|
26
26
|
};
|
|
27
27
|
database?: number;
|
|
28
28
|
}
|