@pi-r/redis 0.7.2 → 0.7.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/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.js CHANGED
@@ -162,7 +162,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
162
162
  parallel = false;
163
163
  }
164
164
  else if (parallel === undefined) {
165
- parallel = !batch.some(item => item.parallel === false);
165
+ parallel = !batch.some(item => item.parallel === false || !!item.update);
166
166
  }
167
167
  if (!parallel) {
168
168
  outResult ||= new Array(length);
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.2",
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.4",
25
- "@e-mc/types": "^0.9.4",
26
- "redis": "^4.6.14"
27
- }
28
- }
1
+ {
2
+ "name": "@pi-r/redis",
3
+ "version": "0.7.4",
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.12",
25
+ "@e-mc/types": "^0.9.12",
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 };