Skip to content

Commit

Permalink
IS-2765: Bruke felles Aiven-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
geir-waagboe committed Nov 18, 2024
1 parent 5027fae commit 88fbc39
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 123 deletions.
30 changes: 0 additions & 30 deletions .github/workflows/redis.yaml

This file was deleted.

7 changes: 3 additions & 4 deletions .nais/naiserator-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ spec:
claims:
extra:
- "NAVident"
redis:
- instance: cache
access: readwrite
envFrom:
- secret: syfooversikt-session-key
- secret: syfooversikt-redis-password
- secret: syfooversikt-unleash-api-token
accessPolicy:
outbound:
Expand All @@ -57,7 +59,6 @@ spec:
- application: syfooversiktsrv
- application: syfoperson
- application: syfoveileder
- application: syfooversikt-redis
- application: flexjar-backend
namespace: flex
- application: modiacontextholder
Expand All @@ -72,8 +73,6 @@ spec:
value: 'production'
- name: AUTH_REDIRECT_URI
value: "https://syfooversikt.intern.dev.nav.no/oauth2/callback"
- name: REDIS_HOST
value: "syfooversikt-redis"
- name: EREG_HOST
value: "https://ereg-services-q1.dev-fss-pub.nais.io"
- name: SYFOOVERSIKTSRV_AAD_APP_CLIENT_ID
Expand Down
7 changes: 3 additions & 4 deletions .nais/naiserator-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ spec:
claims:
extra:
- "NAVident"
redis:
- instance: cache
access: readwrite
envFrom:
- secret: syfooversikt-session-key
- secret: syfooversikt-redis-password
- secret: syfooversikt-unleash-api-token
accessPolicy:
outbound:
Expand All @@ -57,7 +59,6 @@ spec:
- application: syfooversiktsrv
- application: syfoperson
- application: syfoveileder
- application: syfooversikt-redis
- application: flexjar-backend
namespace: flex
- application: modiacontextholder
Expand All @@ -71,8 +72,6 @@ spec:
value: 'production'
- name: AUTH_REDIRECT_URI
value: "https://syfooversikt.intern.nav.no/oauth2/callback"
- name: REDIS_HOST
value: "syfooversikt-redis"
- name: EREG_HOST
value: "https://ereg-services.prod-fss-pub.nais.io"
- name: SYFOOVERSIKTSRV_AAD_APP_CLIENT_ID
Expand Down
32 changes: 0 additions & 32 deletions .nais/redis/redis.yaml

This file was deleted.

34 changes: 0 additions & 34 deletions .nais/redis/redisexporter.yaml

This file was deleted.

4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,4 @@ Se denne siden for [testdata](https://confluence.adeo.no/pages/viewpage.action?p

## Redis Cache

Brukes for å cache bruker-sessions. Nais-oppsettet ligger i `.nais/redis.yaml`.
Redis pod deployes automatisk ved endringer i workflow eller config i master,
men kan også deployes manuelt til NAIS ved å kjøre følgdende kommando: `kubectl apply -f .nais/redis.yaml`.
Bruker teamsykefravr sin felles Redis-cache på Aiven for å cache bruker-sessions.
10 changes: 4 additions & 6 deletions server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,8 @@ export const unleash: { serverApiUrl: string; serverApiToken: string } = {
};

export const redis = {
host: envVar({ name: 'REDIS_HOST', defaultValue: '' }),
port: Number.parseInt(envVar({ name: 'REDIS_PORT', defaultValue: '6379' })),
password: envVar({
name: 'REDIS_PASSWORD',
defaultValue: { dev: '', prod: '' },
}),
uri: envVar({ name: 'REDIS_URI_CACHE', defaultValue: '' }),
username: envVar({ name: 'REDIS_USERNAME_CACHE', defaultValue: '' }),
password: envVar({ name: 'REDIS_PASSWORD_CACHE', defaultValue: '' }),
database: 20,
};
21 changes: 11 additions & 10 deletions server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@ const SESSION_MAX_AGE_MILLIS = 12 * 60 * 60 * 1000;

const SESSION_MAX_AGE_SECONDS = SESSION_MAX_AGE_MILLIS / 1000;

const getRedisStore = () => {
if (Config.isDev) return undefined;

const RedisStore = connectRedis(session);

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

const getRedisStore = () => {
if (Config.isDev) return undefined;
const RedisStore = connectRedis(session);
return new RedisStore({
client: redisClient,
client: getRedisClient(),
ttl: SESSION_MAX_AGE_SECONDS,
disableTouch: true,
});
Expand Down

0 comments on commit 88fbc39

Please sign in to comment.