File size: 632 Bytes
ceb943f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { Redis } from '@upstash/redis';

// No-op client for local dev when Upstash isn't configured.
// All cache reads return null (fall through to DB), writes are skipped.
const noopRedis = {
    get: async () => null,
    set: async () => null,
    del: async () => null,
    incr: async () => 1,
    expire: async () => null,
} as unknown as Redis;

export const redis: Redis =
    process.env.UPSTASH_REDIS_REST_URL && process.env.UPSTASH_REDIS_REST_TOKEN
        ? new Redis({
              url: process.env.UPSTASH_REDIS_REST_URL,
              token: process.env.UPSTASH_REDIS_REST_TOKEN,
          })
        : noopRedis;