@vbarbarosh/node-helpers 2.3.0 → 2.4.0

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "Vladimir Barbarosh <vladimir.barbarosh@gmail.com>",
3
3
  "license": "MIT",
4
4
  "name": "@vbarbarosh/node-helpers",
5
- "version": "2.3.0",
5
+ "version": "2.4.0",
6
6
  "description": "A set of helpers for JavaScript/Node.js",
7
7
  "files": [
8
8
  "src"
@@ -1,21 +1,29 @@
1
- const Redis = require('redis');
1
+ const redis = require('redis');
2
2
 
3
- /**
4
- * tls://11.11.11.11:6378?ip-google=11.11.11.11&ip-external=22.22.22.22&password=xx-xx-xx&ssl[verify_peer]=0&ssl[verify_peer_name]=0
5
- *
6
- * @param url
7
- * @returns {*}
8
- */
9
- function redis_connect(url)
3
+ // tcp://127.0.0.1:6379
4
+ // tls://11.11.11.11:6378?password=xxx
5
+ // tls://11.11.11.11:6378?password=xx-xx-xx&ssl[verify_peer]=0&ssl[verify_peer_name]=0
6
+ async function redis_connect(url)
10
7
  {
8
+ const tmp = new URL(url);
9
+ const password = tmp.password || tmp.searchParams.get('password');
10
+
11
11
  if (url.match(/^tls:/)) {
12
- return Redis.createClient(url.replace(/^tls:/, 'rediss:'), {
13
- tls: {
14
- rejectUnauthorized: false,
15
- },
12
+ const out = redis.createClient({
13
+ url: url.replace(/^tls:/, 'rediss:'),
14
+ password,
15
+ tls: {rejectUnauthorized: false},
16
+ socket: {tls: true, rejectUnauthorized: false},
16
17
  });
18
+ await out.connect();
19
+ return out;
17
20
  }
18
- return Redis.createClient(url.replace(/^tcp:/, 'redis:'));
21
+ const out = await redis.createClient({
22
+ url: url.replace(/^tcp:/, 'redis:'),
23
+ password,
24
+ });
25
+ await out.connect();
26
+ return out;
19
27
  }
20
28
 
21
29
  module.exports = redis_connect;