diff --git a/.changeset/chilled-items-trade.md b/.changeset/chilled-items-trade.md new file mode 100644 index 0000000000..b069885498 --- /dev/null +++ b/.changeset/chilled-items-trade.md @@ -0,0 +1,13 @@ +--- +'@backstage/backend-common': minor +--- + +**BREAKING**: The connection string for `redis` cache store now requires a protocol prefix. + +```diff +backend: + cache: + store: redis +- connection: user:pass@cache.example.com:6379 ++ connection: redis://user:pass@cache.example.com:6379 +``` diff --git a/docs/overview/architecture-overview.md b/docs/overview/architecture-overview.md index 358dc53852..5b6b81cf10 100644 --- a/docs/overview/architecture-overview.md +++ b/docs/overview/architecture-overview.md @@ -310,7 +310,7 @@ backend: backend: cache: store: redis - connection: user:pass@cache.example.com:6379 + connection: redis://user:pass@cache.example.com:6379 ``` Contributions supporting other cache stores are welcome! diff --git a/packages/backend-common/config.d.ts b/packages/backend-common/config.d.ts index 57645d9fda..0c3e3132c0 100644 --- a/packages/backend-common/config.d.ts +++ b/packages/backend-common/config.d.ts @@ -137,7 +137,7 @@ export interface Config { | { store: 'redis'; /** - * A redis connection string in the form `user:pass@host:port`. + * A redis connection string in the form `redis://user:pass@host:port`. * @secret */ connection: string; diff --git a/packages/backend-common/src/cache/CacheManager.test.ts b/packages/backend-common/src/cache/CacheManager.test.ts index 660aa82bb0..c6cad2e49b 100644 --- a/packages/backend-common/src/cache/CacheManager.test.ts +++ b/packages/backend-common/src/cache/CacheManager.test.ts @@ -195,14 +195,13 @@ describe('CacheManager', () => { }); it('returns a Redis client when configured', () => { - const redisHostAndPort = '127.0.0.1:6379'; - const expectedHost = `redis://${redisHostAndPort}`; + const redisConnection = 'redis://127.0.0.1:6379'; const manager = CacheManager.fromConfig( new ConfigReader({ backend: { cache: { store: 'redis', - connection: redisHostAndPort, + connection: redisConnection, }, }, }), @@ -218,7 +217,7 @@ describe('CacheManager', () => { expect(mockCacheCalls[0][0].store).toBeInstanceOf(KeyvRedis); const redis = KeyvRedis as jest.Mock; const mockRedisCalls = redis.mock.calls.splice(-1); - expect(mockRedisCalls[0][0]).toEqual(expectedHost); + expect(mockRedisCalls[0][0]).toEqual(redisConnection); }); describe('connection errors', () => { diff --git a/packages/backend-common/src/cache/CacheManager.ts b/packages/backend-common/src/cache/CacheManager.ts index d63ac6d940..d8652e42d8 100644 --- a/packages/backend-common/src/cache/CacheManager.ts +++ b/packages/backend-common/src/cache/CacheManager.ts @@ -133,7 +133,7 @@ export class CacheManager { return new Keyv({ namespace: pluginId, ttl: defaultTtl, - store: new KeyvRedis(`redis://${this.connection}`), + store: new KeyvRedis(this.connection), }); }