redis.ts 600 B

1234567891011121314151617181920212223
  1. import { promisify } from "util";
  2. import redis from "redis";
  3. const client = redis.createClient({
  4. host: process.env.REDIS_HOST || "127.0.0.1",
  5. port: Number(process.env.REDIS_PORT) || 6379,
  6. ...(process.env.REDIS_PASSWORD && { password: process.env.REDIS_PASSWORD })
  7. });
  8. export const get: (key: string) => Promise<any> = promisify(client.get).bind(
  9. client
  10. );
  11. export const set: (
  12. key: string,
  13. value: string,
  14. ex?: string,
  15. exValue?: number
  16. ) => Promise<any> = promisify(client.set).bind(client);
  17. export const del: (key: string) => Promise<any> = promisify(client.del).bind(
  18. client
  19. );