Skip to content

Commit c35dc8b

Browse files
Flag the SDK as ready from cache immediately when using Redis storage
1 parent 6b11bd6 commit c35dc8b

File tree

6 files changed

+13
-6
lines changed

6 files changed

+13
-6
lines changed

CHANGES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
2.2.1 (May 7, 2025)
2-
- Updated Redis storage to avoid lazy require of the `ioredis` dependency when the SDK is initialized.
2+
- Updated the Redis storage to avoid lazy require of the `ioredis` dependency when the SDK is initialized, and allow queueing feature flag evaluations before SDK_READY event is emitted (Reverted in v1.7.0).
33

44
2.2.0 (March 28, 2025)
55
- Added a new optional argument to the client `getTreatment` methods to allow passing additional evaluation options, such as a map of properties to append to the generated impressions sent to Split backend. Read more in our docs.

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@splitsoftware/splitio-commons",
3-
"version": "2.2.1-rc.2",
3+
"version": "2.2.1-rc.3",
44
"description": "Split JavaScript SDK common components",
55
"main": "cjs/index.js",
66
"module": "esm/index.js",

src/sdkFactory/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import SplitIO from '../../types/splitio';
77
import { validateAndTrackApiKey } from '../utils/inputValidation/apiKey';
88
import { createLoggerAPI } from '../logger/sdkLogger';
99
import { NEW_FACTORY, RETRIEVE_MANAGER } from '../logger/constants';
10-
import { SDK_SPLITS_ARRIVED, SDK_SEGMENTS_ARRIVED } from '../readiness/constants';
10+
import { SDK_SPLITS_ARRIVED, SDK_SEGMENTS_ARRIVED, SDK_SPLITS_CACHE_LOADED } from '../readiness/constants';
1111
import { objectAssign } from '../utils/lang/objectAssign';
1212
import { strategyDebugFactory } from '../trackers/strategy/strategyDebug';
1313
import { strategyOptimizedFactory } from '../trackers/strategy/strategyOptimized';
@@ -52,6 +52,9 @@ export function sdkFactory(params: ISdkFactoryParams): SplitIO.ISDK | SplitIO.IA
5252
readiness.splits.emit(SDK_SPLITS_ARRIVED);
5353
readiness.segments.emit(SDK_SEGMENTS_ARRIVED);
5454
},
55+
onReadyFromCacheCb: () => {
56+
readiness.splits.emit(SDK_SPLITS_CACHE_LOADED);
57+
}
5558
});
5659
// @TODO add support for dataloader: `if (params.dataLoader) params.dataLoader(storage);`
5760
const clients: Record<string, SplitIO.IBasicClient> = {};

src/storages/inRedis/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,17 @@ export function InRedisStorage(options: InRedisStorageOptions = {}): IStorageAsy
3636
function InRedisStorageFactory(params: IStorageFactoryParams): IStorageAsync {
3737
if (!RD) throw new Error('The SDK Redis storage is not available. Your runtime environment must support CommonJS (`require`) to import the ioredis dependency.');
3838

39-
const { onReadyCb, settings, settings: { log } } = params;
39+
const { onReadyFromCacheCb, onReadyCb, settings, settings: { log } } = params;
4040
const metadata = metadataBuilder(settings);
4141
const keys = new KeyBuilderSS(prefix, metadata);
4242
const redisClient = new RD(log, options.options || {});
4343
const telemetry = new TelemetryCacheInRedis(log, keys, redisClient);
4444
const impressionCountsCache = new ImpressionCountsCacheInRedis(log, keys.buildImpressionsCountKey(), redisClient);
4545
const uniqueKeysCache = new UniqueKeysCacheInRedis(log, keys.buildUniqueKeysKey(), redisClient);
4646

47+
// RedisAdapter queues operations before connection
48+
onReadyFromCacheCb();
49+
4750
// subscription to Redis connect event in order to emit SDK_READY event on consumer mode
4851
redisClient.on('connect', () => {
4952
onReadyCb();

src/storages/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ export interface IStorageFactoryParams {
472472
* It is meant for emitting SDK_READY event in consumer mode, and waiting before using the storage in the synchronizer.
473473
*/
474474
onReadyCb: (error?: any) => void,
475+
onReadyFromCacheCb: () => void,
475476
}
476477

477478

0 commit comments

Comments
 (0)