@ikonintegration/ikapi 2.6.5-beta → 2.6.6
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 +1 -1
- package/src/Cache/Redis/IKRedis.js +23 -3
package/package.json
CHANGED
|
@@ -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,14 +104,25 @@ 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
|
-
|
|
112
|
+
...(isV4 ? {
|
|
113
|
+
username: this.config.user,
|
|
114
|
+
socket: {
|
|
115
|
+
...(this.config.enableTLS ? { tls: true } : {}), host: this.config.host
|
|
116
|
+
}
|
|
117
|
+
} : {
|
|
118
|
+
host: this.config.host, user: this.config.user,
|
|
119
|
+
...(this.config.enableTLS ? { tls: {} } /* https://docs.upstash.com/howto/connectwithtls */ : {})
|
|
120
|
+
}),
|
|
102
121
|
password: this.config.password,
|
|
103
|
-
...(this.config.enableTLS ? { tls: {} } /* https://docs.upstash.com/howto/connectwithtls */ : {})
|
|
104
122
|
});
|
|
123
|
+
//redis v4 & v3 compatibility
|
|
105
124
|
if (connection && connection.connect) await connection.connect();
|
|
125
|
+
//
|
|
106
126
|
connection.on('connect', () => {
|
|
107
127
|
this.connection = connection;
|
|
108
128
|
if (this.awaitingConnectionQueue) this.awaitingConnectionQueue.forEach((resolve) => resolve());
|