Skip to content

Commit

Permalink
feat: Allow configuring the logical Redis DB to use (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngrewe authored May 2, 2024
1 parent 2108fd3 commit fbe62e6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Types of changes:
- Security in case of vulnerabilities.

## [Unreleased]
### Added

- Add `REDIS_DB` environment variable to customise the logical Redis database to use.

## [5.5.1] 2023-01-29
### Changed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ The following are the different environment variables that are looked up that al
| REDIS_HOST | Host name of the Redis server | gql-schema-registry-redis |
| REDIS_PORT | Port used when connecting to Redis | 6379 |
| REDIS_SECRET | Password used to connect to Redis | Empty |
| REDIS_DB | Index of the logical redis database | 2 |


For development we rely on docker network and use hostnames from `docker-compose.yml`.
Expand Down
9 changes: 9 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default {
host: process.env.REDIS_HOST || 'gql-schema-registry-redis',
port: process.env.REDIS_PORT || '6379',
secret: process.env.REDIS_SECRET || '',
db: intFor(process.env.REDIS_DB, '2'),
},
'gql-schema-registry-kafka': {
host: process.env.KAFKA_BROKER_HOST || 'gql-schema-registry-kafka',
Expand All @@ -33,3 +34,11 @@ export default {
function booleanFor(variable, defaultValue = 'false') {
return (variable || defaultValue).toLowerCase() === 'true';
}

function intFor(variable, defaultValue = '0') {
const parsed = parseInt(variable || defaultValue);
if (isNaN(parsed)) {
return parseInt(defaultValue);
}
return parsed;
}
3 changes: 2 additions & 1 deletion src/redis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ async function resolveInstance(service) {
port,
username,
secret: password,
db,
} = await diplomat.getServiceInstance(service);

return { host, port, username, password };
return { host, port, username, password, db };
} catch (err) {
logger.warn(err, 'Redis discovery failed');

Expand Down

0 comments on commit fbe62e6

Please sign in to comment.