From 520d8df7a10aaf633f11560883556d478108e853 Mon Sep 17 00:00:00 2001 From: Joe Grigg Date: Tue, 31 Oct 2023 10:43:46 +0000 Subject: [PATCH] Added extra redis cache adapter configuration options no refs - This enables supplying a username to connect to redis with when connection to an individual node rather than a cluster. - It also allows for extra options to be given to the ioredis store used in the background. --- ghost/adapter-cache-redis/lib/AdapterCacheRedis.js | 3 +++ .../test/adapter-cache-redis.test.js | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/ghost/adapter-cache-redis/lib/AdapterCacheRedis.js b/ghost/adapter-cache-redis/lib/AdapterCacheRedis.js index 93644da5b6..9c3a574130 100644 --- a/ghost/adapter-cache-redis/lib/AdapterCacheRedis.js +++ b/ghost/adapter-cache-redis/lib/AdapterCacheRedis.js @@ -13,6 +13,7 @@ class AdapterCacheRedis extends BaseCacheAdapter { * @param {Number} [config.port] - redis port 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 * @param {Number} [config.ttl] - default cached value Time To Live (expiration) in *seconds* * @param {String} [config.keyPrefix] - prefix to use when building a unique cache key, e.g.: 'some_id:image-sizes:' * @param {Boolean} [config.reuseConnection] - specifies if the redis store/connection should be reused within the process @@ -38,7 +39,9 @@ class AdapterCacheRedis extends BaseCacheAdapter { ttl: config.ttl, host: config.host, port: config.port, + username: config.username, password: config.password, + ...config.storeConfig, clusterConfig: config.clusterConfig }; const store = redisStoreFactory.getRedisStore(storeOptions, config.reuseConnection); diff --git a/ghost/adapter-cache-redis/test/adapter-cache-redis.test.js b/ghost/adapter-cache-redis/test/adapter-cache-redis.test.js index 4655c6e808..459ffc94a7 100644 --- a/ghost/adapter-cache-redis/test/adapter-cache-redis.test.js +++ b/ghost/adapter-cache-redis/test/adapter-cache-redis.test.js @@ -27,6 +27,20 @@ describe('Adapter Cache Redis', function () { assert.ok(cache); }); + it('can initialize with storeConfig', async function () { + const cache = new RedisCache({ + username: 'myusername', + storeConfig: { + retryStrategy: false, + lazyConnect: true + }, + reuseConnection: false + }); + assert.ok(cache); + assert.equal(cache.redisClient.options.username, 'myusername'); + assert.equal(cache.redisClient.options.retryStrategy, false); + }); + describe('get', function () { it('can get a value from the cache', async function () { const redisCacheInstanceStub = {