Skip to content

Commit c45eaf4

Browse files
committed
Inkluderer build ids i redis keys
1 parent 2b79988 commit c45eaf4

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

server/cache/redis.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type ConstructorProps = {
2323
export class RedisCache {
2424
private readonly client: ReturnType<typeof createClient>;
2525
private readonly ttl: number;
26+
private readonly keyPrefix = process.env.BUILD_ID;
2627

2728
constructor({ ttl }: ConstructorProps) {
2829
const options = clientOptions[process.env.ENV];
@@ -64,21 +65,27 @@ export class RedisCache {
6465
}
6566

6667
public async get(key: string): Promise<CacheHandlerValue | null> {
67-
const data = await this.client.get(key);
68+
const fullKey = this.getFullKey(key);
69+
70+
const data = await this.client.get(this.getFullKey(fullKey));
6871

6972
if (!data) {
70-
console.log(`Not found in redis: ${key}`);
73+
console.log(`Not found in redis: ${fullKey}`);
7174
return null;
7275
}
7376

74-
console.log(`Found in redis: ${key}`);
77+
console.log(`Found in redis: ${fullKey}`);
7578

7679
return JSON.parse(data) as CacheHandlerValue;
7780
}
7881

7982
public async set(key: string, data: CacheHandlerValue) {
80-
return this.client.set(key, JSON.stringify(data), {
83+
return this.client.set(this.getFullKey(key), JSON.stringify(data), {
8184
EX: this.ttl,
8285
});
8386
}
87+
88+
private getFullKey(key: string) {
89+
return `${this.keyPrefix}_${key}`;
90+
}
8491
}

0 commit comments

Comments
 (0)