dh_demo

DreamHanks demo project
git clone git://git.lair.cx/dh_demo
Log | Files | Refs | README

redis.ts (568B)


      1 import { parseIntOrDefault } from '@/lib/utils/number'
      2 import { createClient, RedisClientType } from 'redis'
      3 
      4 const REDIS_CLIENT_NAME = 'wiki'
      5 
      6 let client: RedisClientType | null
      7 
      8 export async function getRedis () {
      9   if (client != null) {
     10     return client
     11   }
     12 
     13   client = createClient({
     14     url: process.env.WIKI_REDIS_URL,
     15     username: process.env.WIKI_REDIS_USERNAME,
     16     password: process.env.WIKI_REDIS_PASSWORD,
     17     name: REDIS_CLIENT_NAME,
     18     database: parseIntOrDefault(process.env.WIKI_REDIS_DATABASE, 0),
     19   })
     20 
     21   await client.connect()
     22   return client
     23 }
     24