Skip to content

Commit

Permalink
IS-3066: Bytter til Valkey (#1636)
Browse files Browse the repository at this point in the history
  • Loading branch information
geir-waagboe authored Feb 11, 2025
1 parent 520e9b0 commit 4c0a941
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .nais/naiserator-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ spec:
claims:
extra:
- "NAVident"
redis:
valkey:
- instance: cache
access: readwrite
accessPolicy:
Expand Down
2 changes: 1 addition & 1 deletion .nais/naiserator-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ spec:
claims:
extra:
- "NAVident"
redis:
valkey:
- instance: cache
access: readwrite
accessPolicy:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ $ cp .env.template .env # for å sette opp lokale miljøvariabler
$ npm install # installerer avhengigheter
```

## Redis Cache
## Valkey Cache

Bruker teamsykefravr sin felles Redis-cache på Aiven for å cache bruker-sessions.
Bruker teamsykefravr sin felles Valkey-cache på Aiven for å cache bruker-sessions.

## Event tracking

Expand Down
13 changes: 8 additions & 5 deletions server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,13 @@ export const auth = {
},
};

export const redis = {
uri: envVar({ name: "REDIS_URI_CACHE", defaultValue: "" }),
username: envVar({ name: "REDIS_USERNAME_CACHE", defaultValue: "" }),
password: envVar({ name: "REDIS_PASSWORD_CACHE", defaultValue: "" }),
export const valkey = {
uri: envVar({ name: "VALKEY_URI_CACHE", defaultValue: "" }).replace(
"valkeys",
"rediss"
),
username: envVar({ name: "VALKEY_USERNAME_CACHE", defaultValue: "" }),
password: envVar({ name: "VALKEY_PASSWORD_CACHE", defaultValue: "" }),
database: 18,
};

Expand All @@ -427,7 +430,7 @@ module.exports = {
auth: auth,
isDev: isDev,
isProd: isProd,
redis: redis,
valkey: valkey,
unleash: unleash,
server: server,
};
18 changes: 9 additions & 9 deletions server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ const SESSION_MAX_AGE_MILLIS = 12 * 60 * 60 * 1000;

const SESSION_MAX_AGE_SECONDS = SESSION_MAX_AGE_MILLIS / 1000;

const getRedisClient = () => {
const redisClient = redis.createClient({
url: Config.redis.uri,
const getValkeyClient = () => {
const valkeyClient = redis.createClient({
url: Config.valkey.uri,
no_ready_check: true,
});
redisClient.auth(Config.redis.password, Config.redis.username);
redisClient.select(Config.redis.database);
return redisClient;
valkeyClient.auth(Config.valkey.password, Config.valkey.username);
valkeyClient.select(Config.valkey.database);
return valkeyClient;
};

const getRedisStore = () => {
const getValkeyStore = () => {
if (Config.isDev) return undefined;
const RedisStore = connectRedis(session);
return new RedisStore({
client: getRedisClient(),
client: getValkeyClient(),
ttl: SESSION_MAX_AGE_SECONDS,
disableTouch: true,
});
Expand All @@ -45,7 +45,7 @@ export const setupSession = (app: express.Application) => {
resave: true,
saveUninitialized: false,
unset: "destroy",
store: getRedisStore(),
store: getValkeyStore(),
rolling: true,
})
);
Expand Down

0 comments on commit 4c0a941

Please sign in to comment.