Skip to content

Commit

Permalink
tweaks to expiry
Browse files Browse the repository at this point in the history
  • Loading branch information
dholms committed Dec 5, 2023
1 parent 2a6fe49 commit 2fac3a3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/bsky/src/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ export class Redis {

async set(key: string, val: string | number, ttlMs?: number) {
if (ttlMs !== undefined) {
return this.setMulti({ [key]: val })
await this.driver.set(this.ns(key), val, 'PX', ttlMs)
} else {
await this.driver.set(this.ns(key), val)
}
await this.driver.set(this.ns(key), val)
}

async getMulti(keys: string[]) {
Expand All @@ -126,9 +127,10 @@ export class Redis {
async setMulti(vals: Record<string, string | number>, ttlMs?: number) {
let builder = this.driver.multi({ pipeline: true })
for (const key of Object.keys(vals)) {
builder = builder.set(this.ns(key), vals[key])
if (ttlMs !== undefined) {
builder = builder.pexpire(key, ttlMs)
builder = builder.set(this.ns(key), vals[key], 'PX', ttlMs)
} else {
builder = builder.set(this.ns(key), vals[key])
}
}
await builder.exec()
Expand Down

0 comments on commit 2fac3a3

Please sign in to comment.