Skip to content

Commit 9a31085

Browse files
committed
handle potentially broken cache value
1 parent 1fe3a1b commit 9a31085

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

packages/cache/redis/src/index.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,15 @@ export default class RedisCache<V = string> implements KeyValueCache<V>, Disposa
146146

147147
set(key: string, value: V, options?: KeyValueCacheSetOptions): Promise<any> {
148148
return this.tracer.startActiveSpan('hive.cache.set', async span => {
149-
const stringifiedValue = JSON.stringify(value);
150-
if (options?.ttl && options.ttl > 0) {
151-
return this.client
152-
.set(key, stringifiedValue, 'PX', options.ttl * 1000)
153-
.finally(() => span.end());
154-
} else {
155-
return this.client.set(key, stringifiedValue).finally(() => span.end());
149+
try {
150+
const stringifiedValue = JSON.stringify(value);
151+
if (options?.ttl && options.ttl > 0) {
152+
return await this.client.set(key, stringifiedValue, 'PX', options.ttl * 1000);
153+
} else {
154+
return await this.client.set(key, stringifiedValue);
155+
}
156+
} finally {
157+
span.end();
156158
}
157159
});
158160
}

0 commit comments

Comments
 (0)