Skip to content

Commit 4dcd24b

Browse files
Lazy require of ioredis
1 parent e5eca00 commit 4dcd24b

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
1.15.1 (May 28, 2024)
2+
- Updated the Redis storage to import `ioredis` dependency when the storage is created, to avoid errors when the SDK is imported or bundled in a .mjs file, since `ioredis` is a CommonJS module.
23
- Bugfixing - Restored some input validation error logs that were removed in version 1.12.0. The logs inform the user when the `getTreatment(s)` methods are called with an invalid value as feature flag name or flag set name.
34

45
1.15.0 (May 13, 2024)

src/storages/inRedis/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RedisAdapter } from './RedisAdapter';
1+
import type { RedisAdapter } from './RedisAdapter';
22
import { IStorageAsync, IStorageAsyncFactory, IStorageFactoryParams } from '../types';
33
import { validatePrefix } from '../KeyBuilder';
44
import { KeyBuilderSS } from '../KeyBuilderSS';
@@ -23,13 +23,17 @@ export interface InRedisStorageOptions {
2323
*/
2424
export function InRedisStorage(options: InRedisStorageOptions = {}): IStorageAsyncFactory {
2525

26+
// Lazy loading to prevent error when bundling or importing the SDK in a .mjs file, since ioredis is a CommonJS module.
27+
// Redis storage is not supported with .mjs files.
28+
const RD = require('./RedisAdapter').RedisAdapter;
29+
2630
const prefix = validatePrefix(options.prefix);
2731

2832
function InRedisStorageFactory(params: IStorageFactoryParams): IStorageAsync {
2933
const { onReadyCb, settings, settings: { log, sync: { impressionsMode } } } = params;
3034
const metadata = metadataBuilder(settings);
3135
const keys = new KeyBuilderSS(prefix, metadata);
32-
const redisClient = new RedisAdapter(log, options.options || {});
36+
const redisClient: RedisAdapter = new RD(log, options.options || {});
3337
const telemetry = new TelemetryCacheInRedis(log, keys, redisClient);
3438
const impressionCountsCache = impressionsMode !== DEBUG ? new ImpressionCountsCacheInRedis(log, keys.buildImpressionsCountKey(), redisClient) : undefined;
3539
const uniqueKeysCache = impressionsMode === NONE ? new UniqueKeysCacheInRedis(log, keys.buildUniqueKeysKey(), redisClient) : undefined;

0 commit comments

Comments
 (0)