Skip to content

Commit

Permalink
redis: Require a maxmemory-policy of volatile-ttl
Browse files Browse the repository at this point in the history
This is the assumed expectation based on our Redis configuration in
production, but as with the last commit, its better to make this an
explicit assertion.  It ensures we don't accidentally misconfigure Redis
in the future and then later run into lost sessions and missed staleness
markers by surprise.
  • Loading branch information
tsibley committed Oct 12, 2023
1 parent f360986 commit e40645e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ if (PRODUCTION && !REVIEW_APP && !REDIS) {
throw new Error("REDIS_URL required in production mode");
}

if (REDIS) {
/* Use "info memory" command instead of "config get maxmemory-policy" since
* Heroku Redis disables admin commands, which includes "config".
*/
const memoryInfo = new Map(
(await REDIS.info("memory"))
.split(/\r\n/)
.map(line => line.match(/^(?<key>[^:]+):(?<value>.*)$/)?.groups)
.filter(matched => matched)
.map(({key, value}) => [key.replace(/_/g, "-"), value])
);
const maxmemoryPolicy = memoryInfo.get("maxmemory-policy");
if (maxmemoryPolicy !== "volatile-ttl") {
throw new Error(`Redis maxmemory-policy is "${maxmemoryPolicy}", but it *must* be "volatile-ttl".`);
}
}


function herokuRedisClient(urlStr) {
const url = new URL(urlStr);
Expand Down

0 comments on commit e40645e

Please sign in to comment.