@pi-r/redis 0.10.0 → 0.10.2

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.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
@@ -34,19 +34,14 @@ async function getClient(db, options, poolKey) {
34
34
  else if (typeof socket.keepAlive !== 'number') {
35
35
  socket.keepAlive = undefined;
36
36
  }
37
- return new Promise((resolve, reject) => {
38
- const client = db.createClient(options);
39
- if (poolKey) {
40
- client.on('end', () => {
41
- delete POOL_STATE[poolKey];
42
- });
43
- }
44
- client.connect()
45
- .then(() => {
46
- resolve(client);
47
- })
48
- .catch(reject);
49
- });
37
+ const client = db.createClient(options);
38
+ if (poolKey) {
39
+ client.on('end', () => {
40
+ delete POOL_STATE[poolKey];
41
+ });
42
+ }
43
+ await client.connect();
44
+ return client;
50
45
  }
51
46
  async function setCredential(item) {
52
47
  const credential = this.getCredential(item);
@@ -105,22 +100,13 @@ async function setCredential(item) {
105
100
  const config = this.getPoolConfig("redis", password);
106
101
  const poolOptions = client.isolationPoolOptions ||= {};
107
102
  if (config) {
108
- const { min, max, idle, queue_max, queue_idle, timeout } = config;
103
+ const { min, max, timeout } = config;
109
104
  if (min >= 0) {
110
105
  poolOptions.min ??= min;
111
106
  }
112
107
  if (max > 0) {
113
108
  poolOptions.max ??= max;
114
109
  }
115
- if (idle > 0) {
116
- poolOptions.idleTimeoutMillis ??= idle;
117
- }
118
- if (queue_max >= 0) {
119
- poolOptions.maxWaitingClients ??= queue_max;
120
- }
121
- if (queue_idle > 0) {
122
- poolOptions.softIdleTimeoutMillis ??= queue_idle;
123
- }
124
110
  if (timeout > 0) {
125
111
  poolOptions.acquireTimeoutMillis ??= timeout;
126
112
  }
@@ -227,6 +213,9 @@ async function executeBatchQuery(batch, options = '', outResult) {
227
213
  const uuidKey = credential.uuidKey ||= (onceCredential ? batch[0] : item).credential?.uuidKey;
228
214
  const targetObject = typeof checkObject === 'string' ? this.hasCoerce("redis", 'options', uuidKey) && (0, types_1.asFunction)(checkObject) : checkObject;
229
215
  const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
216
+ if (command) {
217
+ command.signal ||= this.signal;
218
+ }
230
219
  let queryString = '', rows;
231
220
  if (caching && ignoreCache !== true) {
232
221
  if ((0, types_1.isObject)(search)) {
@@ -634,7 +623,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
634
623
  }
635
624
  }
636
625
  }
637
- return this.processRows(batch, tasks, {
626
+ return this.processRows(batch, tasks, clients.length === 0 ? parallel : {
638
627
  parallel,
639
628
  disconnect() {
640
629
  for (const item of clients) {
package/client/pool.js CHANGED
@@ -2,6 +2,7 @@
2
2
  const DbPool = require('@e-mc/db/pool');
3
3
  const POOL_ACTIVE = new WeakSet();
4
4
  class RedisPool extends DbPool {
5
+ static CACHE_IGNORE = ['modules', 'functions', 'scripts'];
5
6
  static asString(credential) {
6
7
  if (credential.url) {
7
8
  return JSON.stringify(credential);
@@ -9,6 +10,9 @@ class RedisPool extends DbPool {
9
10
  return super.asString(credential);
10
11
  }
11
12
  static sanitize(credential) {
13
+ if (!this.canCache(credential)) {
14
+ return;
15
+ }
12
16
  if (!POOL_ACTIVE.has(credential) || credential.uuidKey) {
13
17
  return credential;
14
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/redis",
3
- "version": "0.10.0",
3
+ "version": "0.10.2",
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.12.0",
24
- "@e-mc/types": "^0.12.0",
25
- "redis": "^4.7.0"
23
+ "@e-mc/db": "^0.12.5",
24
+ "@e-mc/types": "^0.12.5",
25
+ "redis": "^4.7.1"
26
26
  }
27
27
  }
package/types/index.d.ts CHANGED
@@ -4,7 +4,6 @@ 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
7
  import type { RedisJSON } from '@redis/json/dist/commands';
9
8
  import type { ClientCommandOptions } from '@redis/client/dist/lib/client';
10
9
  import type { RedisCommandArgument } from '@redis/client/dist/lib/commands';
@@ -12,7 +11,7 @@ import type { CommandOptions } from '@redis/client/dist/lib/command-options';
12
11
  import type { AggregateOptions } from '@redis/search/dist/commands/AGGREGATE';
13
12
  import type { HScanTuple } from '@redis/client/dist/lib/commands/HSCAN';
14
13
  import type { ScanOptions } from '@redis/client/dist/lib/commands/generic-transformers';
15
- import type { RediSearchSchema, SearchOptions, SetOptions } from 'redis';
14
+ import type { RediSearchSchema, RedisClientOptions, SearchOptions, SetOptions } from 'redis';
16
15
 
17
16
  export interface RedisDataSource extends DbDataSource<string, PlainObject, RedisSetValue | RedisSetValue[] | RedisJSONValue | RedisJSONValue[], RedisCredential, string>, CascadeAction, AuthValue {
18
17
  source: "redis";