@pi-r/redis 0.7.3 → 0.7.5
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 +6 -6
- package/README.md +6 -6
- package/client/index.d.ts +6 -6
- package/client/index.js +1 -1
- package/client/pool.js +36 -0
- package/package.json +28 -28
- package/types/index.d.ts +82 -82
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Copyright 2024 An Pham
|
|
2
|
-
|
|
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
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
7
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
### @pi-r/redis
|
|
2
|
-
|
|
3
|
-
https://e-mc.readthedocs.io/en/latest/db/redis.html
|
|
4
|
-
|
|
5
|
-
### LICENSE
|
|
6
|
-
|
|
1
|
+
### @pi-r/redis
|
|
2
|
+
|
|
3
|
+
https://e-mc.readthedocs.io/en/latest/db/redis.html
|
|
4
|
+
|
|
5
|
+
### LICENSE
|
|
6
|
+
|
|
7
7
|
MIT
|
package/client/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { IDbSourceClient } from '@e-mc/db/types';
|
|
2
|
-
|
|
3
|
-
import type { RedisDataSource } from '../types';
|
|
4
|
-
|
|
5
|
-
declare const Redis: IDbSourceClient<RedisDataSource>;
|
|
6
|
-
|
|
1
|
+
import type { IDbSourceClient } from '@e-mc/db/types';
|
|
2
|
+
|
|
3
|
+
import type { RedisDataSource } from '../types';
|
|
4
|
+
|
|
5
|
+
declare const Redis: IDbSourceClient<RedisDataSource>;
|
|
6
|
+
|
|
7
7
|
export = Redis;
|
package/client/index.js
CHANGED
|
@@ -570,7 +570,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
570
570
|
break;
|
|
571
571
|
default:
|
|
572
572
|
if (item.field) {
|
|
573
|
-
data = client.hGet(...command ? [command, key, item.field] : [key, item.field]);
|
|
573
|
+
data = await client.hGet(...command ? [command, key, item.field] : [key, item.field]);
|
|
574
574
|
}
|
|
575
575
|
else {
|
|
576
576
|
data = await client.hGetAll(...command ? [command, key] : [key]);
|
package/client/pool.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const DbPool = require('@e-mc/db/pool');
|
|
3
|
+
const POOL_ACTIVE = new WeakSet();
|
|
4
|
+
class RedisPool extends DbPool {
|
|
5
|
+
static asString(credential) {
|
|
6
|
+
if (credential.url) {
|
|
7
|
+
return JSON.stringify(credential);
|
|
8
|
+
}
|
|
9
|
+
return super.asString(credential);
|
|
10
|
+
}
|
|
11
|
+
static sanitize(credential) {
|
|
12
|
+
if (!POOL_ACTIVE.has(credential) || credential.uuidKey) {
|
|
13
|
+
return credential;
|
|
14
|
+
}
|
|
15
|
+
if ('socket' in credential || 'isolationPoolOptions' in credential) {
|
|
16
|
+
return { ...credential, socket: credential.socket?.tls ? { tls: true } : undefined, isolationPoolOptions: undefined };
|
|
17
|
+
}
|
|
18
|
+
return credential;
|
|
19
|
+
}
|
|
20
|
+
async getConnection(credential) {
|
|
21
|
+
if (credential) {
|
|
22
|
+
POOL_ACTIVE.add(credential);
|
|
23
|
+
}
|
|
24
|
+
return this.client;
|
|
25
|
+
}
|
|
26
|
+
async close() {
|
|
27
|
+
return this.client.disconnect();
|
|
28
|
+
}
|
|
29
|
+
isEmpty() {
|
|
30
|
+
return this.closed;
|
|
31
|
+
}
|
|
32
|
+
get closed() {
|
|
33
|
+
return !this.client.isOpen;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
module.exports = RedisPool;
|
package/package.json
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@pi-r/redis",
|
|
3
|
-
"version": "0.7.
|
|
4
|
-
"description": "Redis client driver for E-mc.",
|
|
5
|
-
"main": "client/index.js",
|
|
6
|
-
"types": "client/index.d.ts",
|
|
7
|
-
"publishConfig": {
|
|
8
|
-
"access": "public"
|
|
9
|
-
},
|
|
10
|
-
"repository": {
|
|
11
|
-
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
13
|
-
"directory": "src/db/redis"
|
|
14
|
-
},
|
|
15
|
-
"keywords": [
|
|
16
|
-
"squared",
|
|
17
|
-
"e-mc",
|
|
18
|
-
"squared-functions"
|
|
19
|
-
],
|
|
20
|
-
"author": "An Pham <anpham6@gmail.com>",
|
|
21
|
-
"license": "MIT",
|
|
22
|
-
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
23
|
-
"dependencies": {
|
|
24
|
-
"@e-mc/db": "^0.9.
|
|
25
|
-
"@e-mc/types": "^0.9.
|
|
26
|
-
"redis": "^4.
|
|
27
|
-
}
|
|
28
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@pi-r/redis",
|
|
3
|
+
"version": "0.7.5",
|
|
4
|
+
"description": "Redis client driver for E-mc.",
|
|
5
|
+
"main": "client/index.js",
|
|
6
|
+
"types": "client/index.d.ts",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
13
|
+
"directory": "src/db/redis"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"squared",
|
|
17
|
+
"e-mc",
|
|
18
|
+
"squared-functions"
|
|
19
|
+
],
|
|
20
|
+
"author": "An Pham <anpham6@gmail.com>",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@e-mc/db": "^0.9.18",
|
|
25
|
+
"@e-mc/types": "^0.9.18",
|
|
26
|
+
"redis": "^4.7.0"
|
|
27
|
+
}
|
|
28
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
import type { DbDataSource } from '@e-mc/types/lib/squared';
|
|
2
|
-
|
|
3
|
-
import type { CascadeAction, ServerAuth } from '@e-mc/types/lib/db';
|
|
4
|
-
|
|
5
|
-
import type { CommandOptions } from '@redis/client/dist/lib/command-options';
|
|
6
|
-
import type { ClientCommandOptions } from '@redis/client/dist/lib/client';
|
|
7
|
-
import type { RedisClientOptions } from '@redis/client';
|
|
8
|
-
import type { RedisCommandArgument } from '@redis/client/dist/lib/commands';
|
|
9
|
-
import type { RedisJSON } from '@redis/json/dist/commands';
|
|
10
|
-
import type { RediSearchSchema, SearchOptions, SetOptions } from 'redis';
|
|
11
|
-
|
|
12
|
-
export interface RedisDataSource extends DbDataSource<string, PlainObject, ArrayOf<RedisSetValue> | ArrayOf<RedisJSONValue>, RedisCredential, string>, CascadeAction, AuthValue {
|
|
13
|
-
source: "redis";
|
|
14
|
-
key?: ArrayOf<RedisCommandArgument>;
|
|
15
|
-
field?: RedisCommandArgument;
|
|
16
|
-
path?: string;
|
|
17
|
-
format?: RedisFormat | "HKEYS" | "HVALS";
|
|
18
|
-
search?: RedisQuery;
|
|
19
|
-
aggregate?: RedisQuery;
|
|
20
|
-
options?: {
|
|
21
|
-
client?: RedisClientOptions;
|
|
22
|
-
command?: RedisCommandOptions;
|
|
23
|
-
get?: PlainObject;
|
|
24
|
-
search?: SearchOptions;
|
|
25
|
-
aggregate?: PlainObject;
|
|
26
|
-
};
|
|
27
|
-
database?: number;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export type RedisCredential = ServerAuth;
|
|
31
|
-
|
|
32
|
-
export interface RedisCommand<T = "HASH" | "JSON" | undefined, U = unknown, V = unknown> {
|
|
33
|
-
format: T;
|
|
34
|
-
command?: string;
|
|
35
|
-
key?: U;
|
|
36
|
-
value?: V;
|
|
37
|
-
NX?: boolean;
|
|
38
|
-
XX?: boolean;
|
|
39
|
-
options?: {
|
|
40
|
-
set?: SetOptions;
|
|
41
|
-
expire?: { [K in RedisExpireCondition]?: boolean; };
|
|
42
|
-
command?: RedisCommandOptions;
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface RedisSetValue extends RedisCommand<"HASH", RedisCommandArgument, RedisCommandValue | RedisHSETObject> {
|
|
47
|
-
field?: RedisCommandValue | RedisHSETObject;
|
|
48
|
-
EX?: number;
|
|
49
|
-
PX?: number;
|
|
50
|
-
EXAT?: number;
|
|
51
|
-
PXAT?: number;
|
|
52
|
-
KEEPTTL?: boolean;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export interface RedisJSONValue extends RedisCommand<"JSON", string, ArrayOf<RedisJSON>> {
|
|
56
|
-
command?: RedisCommandJSON;
|
|
57
|
-
path?: string;
|
|
58
|
-
start?: number | string;
|
|
59
|
-
stop?: number | string;
|
|
60
|
-
index?: number | string;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export interface RedisQuery {
|
|
64
|
-
index?: string;
|
|
65
|
-
schema?: RediSearchSchema | string;
|
|
66
|
-
query?: string;
|
|
67
|
-
options?: PlainObject;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export interface JsonMSetItem {
|
|
71
|
-
key: RedisCommandArgument;
|
|
72
|
-
path: RedisCommandArgument;
|
|
73
|
-
value: RedisJSON;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export type RedisFormat = "HASH" | "JSON";
|
|
77
|
-
export type RedisCommandJSON = "ARRAPPEND" | "ARRINDEX" | "ARRINSERT" | "ARRPOP" | "ARRTRIM" | "DEL" | "FORGET" | "MERGE" | "MSET" | "NUMINCRBY" | "NUMMULTBY" | "SET" | "STRAPPEND";
|
|
78
|
-
export type RedisExpireCondition = "NX" | "XX" | "GT" | "LT";
|
|
79
|
-
export type RedisCommandValue = RedisCommandArgument | number;
|
|
80
|
-
export type RedisCommandOptions = CommandOptions<ClientCommandOptions>;
|
|
81
|
-
export type RedisHSETObject = Record<number | string, RedisCommandValue>;
|
|
82
|
-
|
|
1
|
+
import type { DbDataSource } from '@e-mc/types/lib/squared';
|
|
2
|
+
|
|
3
|
+
import type { CascadeAction, ServerAuth } from '@e-mc/types/lib/db';
|
|
4
|
+
|
|
5
|
+
import type { CommandOptions } from '@redis/client/dist/lib/command-options';
|
|
6
|
+
import type { ClientCommandOptions } from '@redis/client/dist/lib/client';
|
|
7
|
+
import type { RedisClientOptions } from '@redis/client';
|
|
8
|
+
import type { RedisCommandArgument } from '@redis/client/dist/lib/commands';
|
|
9
|
+
import type { RedisJSON } from '@redis/json/dist/commands';
|
|
10
|
+
import type { RediSearchSchema, SearchOptions, SetOptions } from 'redis';
|
|
11
|
+
|
|
12
|
+
export interface RedisDataSource extends DbDataSource<string, PlainObject, ArrayOf<RedisSetValue> | ArrayOf<RedisJSONValue>, RedisCredential, string>, CascadeAction, AuthValue {
|
|
13
|
+
source: "redis";
|
|
14
|
+
key?: ArrayOf<RedisCommandArgument>;
|
|
15
|
+
field?: RedisCommandArgument;
|
|
16
|
+
path?: string;
|
|
17
|
+
format?: RedisFormat | "HKEYS" | "HVALS";
|
|
18
|
+
search?: RedisQuery;
|
|
19
|
+
aggregate?: RedisQuery;
|
|
20
|
+
options?: {
|
|
21
|
+
client?: RedisClientOptions;
|
|
22
|
+
command?: RedisCommandOptions;
|
|
23
|
+
get?: PlainObject;
|
|
24
|
+
search?: SearchOptions;
|
|
25
|
+
aggregate?: PlainObject;
|
|
26
|
+
};
|
|
27
|
+
database?: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type RedisCredential = ServerAuth;
|
|
31
|
+
|
|
32
|
+
export interface RedisCommand<T = "HASH" | "JSON" | undefined, U = unknown, V = unknown> {
|
|
33
|
+
format: T;
|
|
34
|
+
command?: string;
|
|
35
|
+
key?: U;
|
|
36
|
+
value?: V;
|
|
37
|
+
NX?: boolean;
|
|
38
|
+
XX?: boolean;
|
|
39
|
+
options?: {
|
|
40
|
+
set?: SetOptions;
|
|
41
|
+
expire?: { [K in RedisExpireCondition]?: boolean; };
|
|
42
|
+
command?: RedisCommandOptions;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface RedisSetValue extends RedisCommand<"HASH", RedisCommandArgument, RedisCommandValue | RedisHSETObject> {
|
|
47
|
+
field?: RedisCommandValue | RedisHSETObject;
|
|
48
|
+
EX?: number;
|
|
49
|
+
PX?: number;
|
|
50
|
+
EXAT?: number;
|
|
51
|
+
PXAT?: number;
|
|
52
|
+
KEEPTTL?: boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface RedisJSONValue extends RedisCommand<"JSON", string, ArrayOf<RedisJSON>> {
|
|
56
|
+
command?: RedisCommandJSON;
|
|
57
|
+
path?: string;
|
|
58
|
+
start?: number | string;
|
|
59
|
+
stop?: number | string;
|
|
60
|
+
index?: number | string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface RedisQuery {
|
|
64
|
+
index?: string;
|
|
65
|
+
schema?: RediSearchSchema | string;
|
|
66
|
+
query?: string;
|
|
67
|
+
options?: PlainObject;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface JsonMSetItem {
|
|
71
|
+
key: RedisCommandArgument;
|
|
72
|
+
path: RedisCommandArgument;
|
|
73
|
+
value: RedisJSON;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type RedisFormat = "HASH" | "JSON";
|
|
77
|
+
export type RedisCommandJSON = "ARRAPPEND" | "ARRINDEX" | "ARRINSERT" | "ARRPOP" | "ARRTRIM" | "DEL" | "FORGET" | "MERGE" | "MSET" | "NUMINCRBY" | "NUMMULTBY" | "SET" | "STRAPPEND";
|
|
78
|
+
export type RedisExpireCondition = "NX" | "XX" | "GT" | "LT";
|
|
79
|
+
export type RedisCommandValue = RedisCommandArgument | number;
|
|
80
|
+
export type RedisCommandOptions = CommandOptions<ClientCommandOptions>;
|
|
81
|
+
export type RedisHSETObject = Record<number | string, RedisCommandValue>;
|
|
82
|
+
|
|
83
83
|
export type { RedisCommandArgument, RedisJSON };
|