Skip to content

Commit

Permalink
fix: cache format
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Feb 27, 2024
1 parent ea5f509 commit b4f4071
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/lib/redis.server.ts
Expand Up @@ -57,7 +57,7 @@ export async function cacheGet(options: {
console.error("Redis get error: ", error)
}

const set = (value: string | Record<string, any>) => {
const set = (value: Record<string, any>) => {
if (value) {
if (options.noExpire) {
redis.set(redisKey, JSON.stringify(value))
Expand All @@ -77,7 +77,9 @@ export async function cacheGet(options: {
if (options.durable) {
const ttl = await redis.ttl(redisKey)
if (ttl < (options.expireTime || REDIS_EXPIRE) - options.durable) {
set(cacheValue)
try {
set(JSON.parse(cacheValue))
} catch (error) {}
options.getValueFun().then((value) => {
set(value)
})
Expand Down

0 comments on commit b4f4071

Please sign in to comment.