accept client config for clustered redis
Signed-off-by: Mark Nachazel <markn@doordash.com>
This commit is contained in:
@@ -264,4 +264,57 @@ describe('CacheManager store options', () => {
|
||||
defaults: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it('respects client config for non-clustered mode', () => {
|
||||
const manager = CacheManager.fromConfig(
|
||||
mockServices.rootConfig({
|
||||
data: {
|
||||
backend: {
|
||||
cache: {
|
||||
store: 'redis',
|
||||
connection: 'redis://localhost:6379',
|
||||
redis: {
|
||||
client: {
|
||||
keyPrefixSeparator: '!',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
manager.forPlugin('p1');
|
||||
|
||||
expect(KeyvRedis).toHaveBeenCalledWith('redis://localhost:6379', {
|
||||
keyPrefixSeparator: '!',
|
||||
});
|
||||
});
|
||||
|
||||
it('accepts client config for clustered mode', () => {
|
||||
const manager = CacheManager.fromConfig(
|
||||
mockServices.rootConfig({
|
||||
data: {
|
||||
backend: {
|
||||
cache: {
|
||||
store: 'redis',
|
||||
connection: 'redis://localhost:6379',
|
||||
redis: {
|
||||
client: {
|
||||
keyPrefixSeparator: '!',
|
||||
},
|
||||
cluster: {
|
||||
rootNodes: [{ url: 'redis://localhost:6379' }],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
manager.forPlugin('p1');
|
||||
|
||||
expect(KeyvRedis).toHaveBeenCalledWith(expect.anything(), {
|
||||
keyPrefixSeparator: '!',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -211,15 +211,15 @@ export class CacheManager {
|
||||
|
||||
return (pluginId, defaultTtl) => {
|
||||
if (!stores[pluginId]) {
|
||||
const redisOptions = this.storeOptions?.client || {
|
||||
keyPrefixSeparator: ':',
|
||||
};
|
||||
if (this.storeOptions?.cluster) {
|
||||
// Create a Redis cluster
|
||||
const cluster = createCluster(this.storeOptions?.cluster);
|
||||
stores[pluginId] = new KeyvRedis(cluster);
|
||||
stores[pluginId] = new KeyvRedis(cluster, redisOptions);
|
||||
} else {
|
||||
// Create a regular Redis connection
|
||||
const redisOptions = this.storeOptions?.client || {
|
||||
keyPrefixSeparator: ':',
|
||||
};
|
||||
stores[pluginId] = new KeyvRedis(this.connection, redisOptions);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user