@pi-r/redis 0.6.1 → 0.6.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/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  ### @pi-r/redis
2
2
 
3
+ https://e-mc.readthedocs.io/en/latest/db/redis.html
4
+
3
5
  ### LICENSE
4
6
 
5
7
  MIT
package/client/index.js CHANGED
@@ -46,7 +46,7 @@ function removePoolProperties(options) {
46
46
  }
47
47
  return options;
48
48
  }
49
- const getPoolKey = (options) => options.url + '_' + (options.username || '') + '_' + (options.password || '') + '_' + (options.database ?? '') + '_' + (options.socket?.tls ? '1' : '0') + '_' + (options.legacyMode ? '1' : '0');
49
+ const getPoolKey = (options) => options.url && JSON.stringify(options);
50
50
  async function setCredential(item) {
51
51
  if (!REDIS_V4) {
52
52
  throw (0, types_1.errorValue)("Upgrade client to latest version" /* ERR_DB.UPGRADE */, "redis" /* STRINGS.MODULE_NAME */ + '@' + Db.getPackageVersion("redis" /* STRINGS.MODULE_NAME */));
@@ -99,18 +99,19 @@ async function setCredential(item) {
99
99
  let pool;
100
100
  username = undefined;
101
101
  password = undefined;
102
- if (typeof usePool === 'string' && (username = client.username || (0, util_1.parseConnectionString)(uri)?.username)) {
103
- [password, pool] = DbPool.validateKey(POOL_STATE, username, usePool);
104
- if (pool) {
105
- pool.add(item, password);
102
+ if ((0, types_1.isString)(usePool)) {
103
+ if (username = client.username || (0, util_1.parseConnectionString)(uri)?.username) {
104
+ [password, pool] = DbPool.validateKey(POOL_STATE, username, usePool);
105
+ if (pool) {
106
+ pool.add(item, password);
107
+ return;
108
+ }
109
+ }
110
+ if (!password) {
111
+ item.usePool = '';
106
112
  return;
107
113
  }
108
114
  }
109
- const poolKey = getPoolKey(client);
110
- if ((pool = POOL_STATE[poolKey]) && !pool.closed) {
111
- pool.add(item);
112
- return;
113
- }
114
115
  const config = this.getPoolConfig("redis" /* STRINGS.MODULE_NAME */, password);
115
116
  const poolOptions = client.isolationPoolOptions || (client.isolationPoolOptions = {});
116
117
  if (config) {
@@ -134,6 +135,11 @@ async function setCredential(item) {
134
135
  poolOptions.acquireTimeoutMillis ?? (poolOptions.acquireTimeoutMillis = timeout);
135
136
  }
136
137
  }
138
+ const poolKey = getPoolKey(client);
139
+ if ((pool = POOL_STATE[poolKey]) && !pool.closed) {
140
+ pool.add(item);
141
+ return;
142
+ }
137
143
  try {
138
144
  const target = new RedisPool(await getClient(redis, client, poolKey), poolKey, username && password ? { username, password } : undefined).add(item);
139
145
  target.parent = POOL_STATE;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/redis",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
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.1",
25
- "@e-mc/types": "^0.8.1",
24
+ "@e-mc/db": "^0.8.2",
25
+ "@e-mc/types": "^0.8.2",
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, ExecuteAction, ServerAuth } from '@e-mc/types/lib/db';
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, JMSetItem } from '@redis/client/dist/lib/client';
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
10
  import type { AggregateOptions, RediSearchSchema, SearchOptions, SetOptions } from 'redis';
11
11
 
12
- export interface RedisDataSource extends DbDataSource<string, PlainObject, ArrayOf<RedisSetValue> | ArrayOf<RedisJSONValue>, string | RedisCredential, string>, CascadeAction, AuthValue {
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;