Merge pull request #9888 from kuangp/refactor/redis

refactor(redis): require protocol in connection string
This commit is contained in:
Johan Haals
2022-03-02 09:20:11 +01:00
committed by GitHub
5 changed files with 19 additions and 7 deletions
+13
View File
@@ -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
```
+1 -1
View File
@@ -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!
+1 -1
View File
@@ -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;
+3 -4
View File
@@ -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', () => {
+1 -1
View File
@@ -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),
});
}