@ikonintegration/ikapi 2.6.5-beta → 2.6.5-beta2
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 +20 -2
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
|
|
@@ -97,12 +106,21 @@ export default class IKCache_Redis extends IKCache {
|
|
|
97
106
|
//Instantiate client and initiate connection
|
|
98
107
|
return new Promise((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, 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
|
|
105
122
|
if (connection && connection.connect) await connection.connect();
|
|
123
|
+
//
|
|
106
124
|
connection.on('connect', () => {
|
|
107
125
|
this.connection = connection;
|
|
108
126
|
if (this.awaitingConnectionQueue) this.awaitingConnectionQueue.forEach((resolve) => resolve());
|