Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class AdapterCacheRedis extends BaseCacheAdapter {
* @param {Object} [config.cache] - caching instance compatible with cache-manager's redis store
* @param {String} [config.host] - redis host used in case no cache instance provided
* @param {Number} [config.port] - redis port used in case no cache instance provided
* @param {String} [config.username] - redis username used in case no cache instance provided
* @param {String} [config.password] - redis password used in case no cache instance provided
* @param {Object} [config.clusterConfig] - redis cluster config used in case no cache instance provided
* @param {Object} [config.storeConfig] - extra redis client config used in case no cache instance provided
Expand Down Expand Up @@ -46,7 +47,7 @@ class AdapterCacheRedis extends BaseCacheAdapter {
username: config.username,
password: config.password,
retryStrategy: () => {
return (config.storeConfig.retryConnectSeconds || 10) * 1000;
return (config.storeConfig?.retryConnectSeconds || 10) * 1000;
},
...config.storeConfig,
clusterConfig: config.clusterConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,40 @@ describe('Adapter Cache Redis', function () {
assert.equal(cache.redisClient.options.retryStrategy, false);
});

describe('retryStrategy', function () {
it('does not throw and defaults to 10 seconds when storeConfig is not provided', function () {
const cache = new RedisCache({
reuseConnection: false
});
// retryStrategy is invoked by ioredis whenever Redis becomes unavailable.
// It must not crash even when storeConfig is omitted from the adapter config.
assert.doesNotThrow(() => cache.redisClient.options.retryStrategy(1));
assert.equal(cache.redisClient.options.retryStrategy(1), 10000);
cache.redisClient.disconnect();
});

it('defaults to 10 seconds when retryConnectSeconds is not set in storeConfig', function () {
const cache = new RedisCache({
storeConfig: {
lazyConnect: true
},
reuseConnection: false
});
assert.equal(cache.redisClient.options.retryStrategy(1), 10000);
});

it('uses retryConnectSeconds from storeConfig when provided', function () {
const cache = new RedisCache({
storeConfig: {
lazyConnect: true,
retryConnectSeconds: 5
},
reuseConnection: false
});
assert.equal(cache.redisClient.options.retryStrategy(1), 5000);
});
});

describe('get', function () {
it('can get a value from the cache', async function () {
const redisCacheInstanceStub = {
Expand Down
Loading