Files
helsinki/Pt12/part12-containers-applications/todo-app/todo-backend/redis/index.js
T
2024-09-30 15:32:50 +03:00

27 lines
552 B
JavaScript
Executable File

const redis = require('redis')
const { promisify } = require('util')
const { REDIS_URL } = require('../util/config')
let getAsync
let setAsync
if (!REDIS_URL) {
const redisIsDisabled = () => {
console.log('No REDIS_URL set, Redis is disabled')
return null
}
getAsync = redisIsDisabled
setAsync = redisIsDisabled
} else {
const client = redis.createClient({
url: REDIS_URL
})
getAsync = promisify(client.get).bind(client)
setAsync = promisify(client.set).bind(client)
}
module.exports = {
getAsync,
setAsync
}