Skip to content

Commit

Permalink
feat: use redis namespace for multitenancy
Browse files Browse the repository at this point in the history
  • Loading branch information
lyricalsoul committed Nov 17, 2024
1 parent 26f6422 commit fb37b19
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/caching/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export default class RedisBackend extends CachingBackend {
})
}

#buildKey (key: string) {
return `ditto:${key}`
}

async start () {
try {
await this.client!.connect()
Expand All @@ -36,21 +40,21 @@ export default class RedisBackend extends CachingBackend {
}

async get (key: string): Promise<any | undefined> {
return this.client!.get(key)
return this.client!.get(this.#buildKey(key))
}

async setTTL (key: string, value: any, ttl: number) {
await this.client!.set(key, value, {
await this.client!.set(this.#buildKey(key), value, {
EX: ttl / 1000
})
}

async set (key: string, value: any) {
await this.client!.set(key, value)
await this.client!.set(this.#buildKey(key), value)
}

async delete (key: string) {
await this.client!.del(key)
await this.client!.del(this.#buildKey(key))
}

async clear () {
Expand Down

0 comments on commit fb37b19

Please sign in to comment.