Pasting my Redis file that converts callbacks into promises, in case it's helpful. It's in typescript and typesafe. You should receive intellisense and autocomplete.
import redis from "redis"
import { promisify } from "util"
import { redisHost as host, redisPort as port } from "../../configKeys"
const client = redis.createClient({
port,
host,
})
client.on("connect", () => {
console.log(`Redis Client connected on port ${port}`)
})
client.on("ready", () => {
console.log("Redis Client ready to use..")
})
client.on("error", (err) => {
console.log(err.message)
})
client.on("end", () => {
logCommon.debug("Redis Client disconnected")
})
process.on("SIGINT", () => {
client.quit()
})
export const GET_ASYNC = (promisify<string>(client.GET).bind(
client
) as unknown) as (key: string) => Promise<string | null>
export const SET_ASYNC = (promisify<string, string, string, number>(
client.SET
).bind(client) as unknown) as (
key: string,
value: string,
mode: string,
duration: number
) => Promise<"OK" | null>
export const DELETE_ASYNC = (promisify<string>(client.DEL).bind(
client
) as unknown) as (key: string) => Promise<number | null>
export default client
Import GET_ASYNC
or SET_ASYNC
into the required file and you can use it with async-await like you would a promise.