@splitsoftware/splitio-commons 2.11.1-rc.1 → 2.12.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/CHANGES.txt
CHANGED
|
@@ -19,7 +19,7 @@ var timeout_1 = require("../../utils/promise/timeout");
|
|
|
19
19
|
var sets_1 = require("../../utils/lang/sets");
|
|
20
20
|
var LOG_PREFIX = 'storage:redis-adapter: ';
|
|
21
21
|
// If we ever decide to fully wrap every method, there's a Commander.getBuiltinCommands from ioredis.
|
|
22
|
-
var METHODS_TO_PROMISE_WRAP = ['set', 'exec', 'del', 'get', 'keys', 'sadd', 'srem', 'sismember', 'smembers', 'incr', 'rpush', 'expire', 'mget', 'lrange', 'ltrim', 'hset', 'hincrby', 'popNRaw'];
|
|
22
|
+
var METHODS_TO_PROMISE_WRAP = ['set', 'exec', 'del', 'get', 'keys', 'sadd', 'srem', 'sismember', 'smembers', 'incr', 'decr', 'rpush', 'expire', 'mget', 'lrange', 'ltrim', 'hset', 'hincrby', 'popNRaw', 'hgetall', 'llen', 'hget'];
|
|
23
23
|
var METHODS_TO_PROMISE_WRAP_EXEC = ['pipeline'];
|
|
24
24
|
// Not part of the settings since it'll vary on each storage. We should be removing storage specific logic from elsewhere.
|
|
25
25
|
var DEFAULT_OPTIONS = {
|
|
@@ -37,7 +37,7 @@ var DEFAULT_LIBRARY_OPTIONS = {
|
|
|
37
37
|
};
|
|
38
38
|
/**
|
|
39
39
|
* Redis adapter on top of the library of choice (written with ioredis) for some extra control.
|
|
40
|
-
* Refactored to use Composition
|
|
40
|
+
* Refactored to use Composition instead of Inheritance to support both v4 and v5.
|
|
41
41
|
*/
|
|
42
42
|
var RedisAdapter = /** @class */ (function () {
|
|
43
43
|
function RedisAdapter(log, storageSettings) {
|
|
@@ -53,23 +53,10 @@ var RedisAdapter = /** @class */ (function () {
|
|
|
53
53
|
this._listenToEvents();
|
|
54
54
|
this._setTimeoutWrappers();
|
|
55
55
|
this._setDisconnectWrapper();
|
|
56
|
-
// Return a Proxy. This allows the adapter to act exactly like an extended class.
|
|
57
|
-
// If a method/property is accessed that we didn't explicitly wrap, it forwards it to `this.client`.
|
|
58
|
-
return new Proxy(this, {
|
|
59
|
-
get: function (target, prop) {
|
|
60
|
-
// If the property exists on our wrapper (like wrapped 'get', 'set', or internal methods)
|
|
61
|
-
if (prop in target) {
|
|
62
|
-
return target[prop];
|
|
63
|
-
}
|
|
64
|
-
// If it doesn't exist on our wrapper but exists on the real client (like 'on', 'quit')
|
|
65
|
-
if (target.client && prop in target.client) {
|
|
66
|
-
var val = target.client[prop];
|
|
67
|
-
return typeof val === 'function' ? val.bind(target.client) : val;
|
|
68
|
-
}
|
|
69
|
-
return undefined;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
56
|
}
|
|
57
|
+
RedisAdapter.prototype.on = function (event, listener) {
|
|
58
|
+
return this.client.on(event, listener);
|
|
59
|
+
};
|
|
73
60
|
RedisAdapter.prototype._listenToEvents = function () {
|
|
74
61
|
var _this = this;
|
|
75
62
|
this.client.once('ready', function () {
|
|
@@ -16,7 +16,7 @@ import { timeout } from '../../utils/promise/timeout';
|
|
|
16
16
|
import { setToArray } from '../../utils/lang/sets';
|
|
17
17
|
var LOG_PREFIX = 'storage:redis-adapter: ';
|
|
18
18
|
// If we ever decide to fully wrap every method, there's a Commander.getBuiltinCommands from ioredis.
|
|
19
|
-
var METHODS_TO_PROMISE_WRAP = ['set', 'exec', 'del', 'get', 'keys', 'sadd', 'srem', 'sismember', 'smembers', 'incr', 'rpush', 'expire', 'mget', 'lrange', 'ltrim', 'hset', 'hincrby', 'popNRaw'];
|
|
19
|
+
var METHODS_TO_PROMISE_WRAP = ['set', 'exec', 'del', 'get', 'keys', 'sadd', 'srem', 'sismember', 'smembers', 'incr', 'decr', 'rpush', 'expire', 'mget', 'lrange', 'ltrim', 'hset', 'hincrby', 'popNRaw', 'hgetall', 'llen', 'hget'];
|
|
20
20
|
var METHODS_TO_PROMISE_WRAP_EXEC = ['pipeline'];
|
|
21
21
|
// Not part of the settings since it'll vary on each storage. We should be removing storage specific logic from elsewhere.
|
|
22
22
|
var DEFAULT_OPTIONS = {
|
|
@@ -34,7 +34,7 @@ var DEFAULT_LIBRARY_OPTIONS = {
|
|
|
34
34
|
};
|
|
35
35
|
/**
|
|
36
36
|
* Redis adapter on top of the library of choice (written with ioredis) for some extra control.
|
|
37
|
-
* Refactored to use Composition
|
|
37
|
+
* Refactored to use Composition instead of Inheritance to support both v4 and v5.
|
|
38
38
|
*/
|
|
39
39
|
var RedisAdapter = /** @class */ (function () {
|
|
40
40
|
function RedisAdapter(log, storageSettings) {
|
|
@@ -50,23 +50,10 @@ var RedisAdapter = /** @class */ (function () {
|
|
|
50
50
|
this._listenToEvents();
|
|
51
51
|
this._setTimeoutWrappers();
|
|
52
52
|
this._setDisconnectWrapper();
|
|
53
|
-
// Return a Proxy. This allows the adapter to act exactly like an extended class.
|
|
54
|
-
// If a method/property is accessed that we didn't explicitly wrap, it forwards it to `this.client`.
|
|
55
|
-
return new Proxy(this, {
|
|
56
|
-
get: function (target, prop) {
|
|
57
|
-
// If the property exists on our wrapper (like wrapped 'get', 'set', or internal methods)
|
|
58
|
-
if (prop in target) {
|
|
59
|
-
return target[prop];
|
|
60
|
-
}
|
|
61
|
-
// If it doesn't exist on our wrapper but exists on the real client (like 'on', 'quit')
|
|
62
|
-
if (target.client && prop in target.client) {
|
|
63
|
-
var val = target.client[prop];
|
|
64
|
-
return typeof val === 'function' ? val.bind(target.client) : val;
|
|
65
|
-
}
|
|
66
|
-
return undefined;
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
53
|
}
|
|
54
|
+
RedisAdapter.prototype.on = function (event, listener) {
|
|
55
|
+
return this.client.on(event, listener);
|
|
56
|
+
};
|
|
70
57
|
RedisAdapter.prototype._listenToEvents = function () {
|
|
71
58
|
var _this = this;
|
|
72
59
|
this.client.once('ready', function () {
|
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@ import { setToArray } from '../../utils/lang/sets';
|
|
|
18
18
|
const LOG_PREFIX = 'storage:redis-adapter: ';
|
|
19
19
|
|
|
20
20
|
// If we ever decide to fully wrap every method, there's a Commander.getBuiltinCommands from ioredis.
|
|
21
|
-
const METHODS_TO_PROMISE_WRAP = ['set', 'exec', 'del', 'get', 'keys', 'sadd', 'srem', 'sismember', 'smembers', 'incr', 'rpush', 'expire', 'mget', 'lrange', 'ltrim', 'hset', 'hincrby', 'popNRaw'];
|
|
21
|
+
const METHODS_TO_PROMISE_WRAP = ['set', 'exec', 'del', 'get', 'keys', 'sadd', 'srem', 'sismember', 'smembers', 'incr', 'decr', 'rpush', 'expire', 'mget', 'lrange', 'ltrim', 'hset', 'hincrby', 'popNRaw', 'hgetall', 'llen', 'hget'];
|
|
22
22
|
const METHODS_TO_PROMISE_WRAP_EXEC = ['pipeline'];
|
|
23
23
|
|
|
24
24
|
// Not part of the settings since it'll vary on each storage. We should be removing storage specific logic from elsewhere.
|
|
@@ -45,7 +45,7 @@ interface IRedisCommand {
|
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* Redis adapter on top of the library of choice (written with ioredis) for some extra control.
|
|
48
|
-
* Refactored to use Composition
|
|
48
|
+
* Refactored to use Composition instead of Inheritance to support both v4 and v5.
|
|
49
49
|
*/
|
|
50
50
|
export class RedisAdapter {
|
|
51
51
|
// eslint-disable-next-line no-undef -- Index signature to allow proxying dynamic ioredis methods without TS errors
|
|
@@ -73,23 +73,10 @@ export class RedisAdapter {
|
|
|
73
73
|
this._listenToEvents();
|
|
74
74
|
this._setTimeoutWrappers();
|
|
75
75
|
this._setDisconnectWrapper();
|
|
76
|
+
}
|
|
76
77
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return new Proxy(this, {
|
|
80
|
-
get(target: RedisAdapter, prop: string | symbol) {
|
|
81
|
-
// If the property exists on our wrapper (like wrapped 'get', 'set', or internal methods)
|
|
82
|
-
if (prop in target) {
|
|
83
|
-
return target[prop as keyof RedisAdapter];
|
|
84
|
-
}
|
|
85
|
-
// If it doesn't exist on our wrapper but exists on the real client (like 'on', 'quit')
|
|
86
|
-
if (target.client && prop in target.client) {
|
|
87
|
-
const val = target.client[prop];
|
|
88
|
-
return typeof val === 'function' ? val.bind(target.client) : val;
|
|
89
|
-
}
|
|
90
|
-
return undefined;
|
|
91
|
-
}
|
|
92
|
-
});
|
|
78
|
+
on(event: string, listener: (...args: any[]) => void) {
|
|
79
|
+
return this.client.on(event, listener);
|
|
93
80
|
}
|
|
94
81
|
|
|
95
82
|
_listenToEvents() {
|