import _redis, { RedisClient } from 'redis'; import dotenv from 'dotenv'; import { promisify } from 'util'; dotenv.config(); export class Redis { redis: RedisClient; hdel: (hash: string, field: string) => Promise; hget: (hash: string, field: string) => Promise; hgetall: (key: string) => Promise; hset: (hash: string, field: string, value: any) => Promise; quit: () => Promise; set: ( key: string, value: any, mode?: string, duration?: number ) => Promise; get: (key: string) => Promise; del: (key: string) => Promise; constructor() { this.redis = _redis.createClient({ url: process.env.REDIS_URL, }); this.hdel = promisify(this.redis.hdel).bind(this.redis); this.hget = promisify(this.redis.hget).bind(this.redis); this.hgetall = promisify(this.redis.hgetall).bind(this.redis); this.hset = promisify(this.redis.hset).bind(this.redis); this.set = promisify(this.redis.set).bind(this.redis); this.get = promisify(this.redis.get).bind(this.redis); this.del = promisify(this.redis.del).bind(this.redis); this.quit = promisify(this.redis.quit).bind(this.redis); } } export const redisClient = new Redis();