Skip to content

Commit 1aebe64

Browse files
Update ioredis peer dependency to support v5 and fix type compatibility issues
1 parent 3aabacc commit 1aebe64

7 files changed

Lines changed: 35 additions & 50 deletions

File tree

package-lock.json

Lines changed: 21 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@
4545
"bugs": "https://github.com/splitio/javascript-commons/issues",
4646
"homepage": "https://github.com/splitio/javascript-commons#readme",
4747
"dependencies": {
48-
"@types/ioredis": "^4.28.0",
4948
"tslib": "^2.3.1"
5049
},
5150
"peerDependencies": {
52-
"ioredis": "^4.28.0"
51+
"ioredis": "^4.28.0 || ^5.0.0"
5352
},
5453
"peerDependenciesMeta": {
5554
"ioredis": {
@@ -68,7 +67,7 @@
6867
"eslint-plugin-import": "^2.25.3",
6968
"eslint-plugin-tsdoc": "^0.3.0",
7069
"fetch-mock": "^9.11.0",
71-
"ioredis": "^4.28.0",
70+
"ioredis": "^5.0.0",
7271
"jest": "^27.2.3",
7372
"jest-localstorage-mock": "^2.4.3",
7473
"lodash": "^4.17.21",

src/storages/inRedis/ImpressionCountsCacheInRedis.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class ImpressionCountsCacheInRedis extends ImpressionCountsCacheInMemory
3434
return pipeline.exec()
3535
.then(data => {
3636
// If this is the creation of the key on Redis, set the expiration for it in 3600 seconds.
37-
if (data.length && data.length === keys.length) {
37+
if (data && data.length && data.length === keys.length) {
3838
return this.redis.expire(this.key, TTL_REFRESH);
3939
}
4040
})

src/storages/inRedis/ImpressionsCacheInRedis.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class ImpressionsCacheInRedis implements IImpressionsCacheAsync {
2525
track(impressions: SplitIO.ImpressionDTO[]): Promise<void> { // @ts-ignore
2626
return this.redis.rpush(
2727
this.key,
28-
impressionsToJSON(impressions, this.metadata),
28+
...impressionsToJSON(impressions, this.metadata),
2929
).then(queuedCount => {
3030
// If this is the creation of the key on Redis, set the expiration for it in 1hr.
3131
if (queuedCount === impressions.length) {

src/storages/inRedis/RedisAdapter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export class RedisAdapter extends ioredis {
4242
constructor(log: ILogger, storageSettings: Record<string, any> = {}) {
4343
const options = RedisAdapter._defineOptions(storageSettings);
4444
// Call the ioredis constructor
45+
// @ts-ignore
4546
super(...RedisAdapter._defineLibrarySettings(options));
4647

4748
this.log = log;

src/storages/inRedis/SplitsCacheInRedis.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import type { RedisAdapter } from './RedisAdapter';
1010
/**
1111
* Discard errors for an answer of multiple operations.
1212
*/
13-
function processPipelineAnswer(results: Array<[Error | null, string]>): string[] {
14-
return results.reduce((accum: string[], errValuePair: [Error | null, string]) => {
15-
if (errValuePair[0] === null) accum.push(errValuePair[1]);
13+
function processPipelineAnswer(results: Array<[Error | null, unknown]> | null): string[] {
14+
return results ? results.reduce((accum: string[], errValuePair: [Error | null, unknown]) => {
15+
if (errValuePair[0] === null) accum.push(errValuePair[1] as string);
1616
return accum;
17-
}, []);
17+
}, []) : [];
1818
}
1919

2020
/**
@@ -26,7 +26,7 @@ export class SplitsCacheInRedis extends AbstractSplitsCacheAsync {
2626
private readonly log: ILogger;
2727
private readonly redis: RedisAdapter;
2828
private readonly keys: KeyBuilderSS;
29-
private redisError?: string;
29+
private redisError?: Error;
3030
private readonly flagSetsFilter: string[];
3131

3232
constructor(log: ILogger, keys: KeyBuilderSS, redis: RedisAdapter, splitFiltersValidation?: ISplitFiltersValidation) {
@@ -198,11 +198,11 @@ export class SplitsCacheInRedis extends AbstractSplitsCacheAsync {
198198
*/
199199
getNamesByFlagSets(flagSets: string[]): Promise<Set<string>[]> {
200200
return this.redis.pipeline(flagSets.map(flagSet => ['smembers', this.keys.buildFlagSetKey(flagSet)])).exec()
201-
.then((results) => results.map(([e, value], index) => {
202-
if (e === null) return value;
201+
.then((results) => results ? results.map(([e, value], index) => {
202+
if (e === null) return value as string;
203203

204204
this.log.error(LOG_PREFIX + `Could not read result from get members of flag set ${flagSets[index]} due to an error: ${e}`);
205-
}))
205+
}) : [])
206206
.then(namesByFlagSets => namesByFlagSets.map(namesByFlagSet => new Set(namesByFlagSet)));
207207
}
208208

src/storages/inRedis/UniqueKeysCacheInRedis.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class UniqueKeysCacheInRedis extends UniqueKeysCacheInMemory implements I
3838
});
3939

4040
this.clear();
41-
return this.redis.rpush(this.key, uniqueKeysArray)
41+
return this.redis.rpush(this.key, ...uniqueKeysArray)
4242
.then(data => {
4343
// If this is the creation of the key on Redis, set the expiration for it in 3600 seconds.
4444
if (data === featureNames.length) {

0 commit comments

Comments
 (0)