@ikonintegration/ikapi 2.6.4 → 2.6.5-beta3

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikonintegration/ikapi",
3
- "version": "2.6.4",
3
+ "version": "2.6.5-beta3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "module": "main.js",
@@ -79,6 +79,15 @@ export default class IKCache_Redis extends IKCache {
79
79
  catch (e) { response = false; }
80
80
  return response;
81
81
  }
82
+ _isRedisClientV4() {
83
+ let isV4 = false;
84
+ try {
85
+ const test = require('redis').createClient({});
86
+ if (test.connect) isV4 = true;
87
+ }
88
+ catch (e) { }
89
+ return isV4;
90
+ }
82
91
  async _connect() {
83
92
  //No connection, but waiting connection queue is valid? wait until other promise
84
93
  //fulfill this promire
@@ -95,13 +104,23 @@ export default class IKCache_Redis extends IKCache {
95
104
  localConsole.debug("Starting remote cache connection");
96
105
 
97
106
  //Instantiate client and initiate connection
98
- return new Promise((resolve, reject) => {
107
+ return new Promise(async (resolve, reject) => {
99
108
  const redis = require("redis");
109
+ const isV4 = this._isRedisClientV4();
110
+ //
100
111
  const connection = redis.createClient({
101
- host: this.config.host, user: this.config.user,
112
+ ...(isV4 ? {
113
+ username: this.config.user, url: this.config.host,
114
+ ...(this.config.enableTLS ? { socket: { tls: true } } /* https://docs.upstash.com/howto/connectwithtls */ : {})
115
+ } : {
116
+ host: this.config.host, user: this.config.user,
117
+ ...(this.config.enableTLS ? { tls: {} } /* https://docs.upstash.com/howto/connectwithtls */ : {})
118
+ }),
102
119
  password: this.config.password,
103
- ...(this.config.enableTLS ? { tls: {} } /* https://docs.upstash.com/howto/connectwithtls */ : {})
104
120
  });
121
+ //redis v4 & v3 compatibility
122
+ if (connection && connection.connect) await connection.connect();
123
+ //
105
124
  connection.on('connect', () => {
106
125
  this.connection = connection;
107
126
  if (this.awaitingConnectionQueue) this.awaitingConnectionQueue.forEach((resolve) => resolve());