Something went wrong. Try again.
Monorepo for Aesthetic.Computer aesthetic.computer
Something went wrong. Try again.
JavaScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950// Key Value, 23.08.15.20.29// Implemented in `redis`.
import { createClient } from "redis";
const redisConnectionString = process.env.REDIS_CONNECTION_STRING;const dev = process.env.NETLIFY_DEV;
let client;
async function connect() { if (client && client.isOpen) { console.log("🔵 Redis client is already connected."); return; } client = !dev ? createClient({ url: redisConnectionString }) : createClient(); client.on("error", (err) => console.log("🔴 Redis client error!", err)); await client.connect();}
async function disconnect() { if (!client?.isOpen) return; // Ensure the client is open before quitting await client.quit();}
async function set(collection, key, value) { await client.HSET(collection, key, value);}
async function del(collection, key) { await client.HDEL(collection, key);}
async function get(collection, key) { return await client.HGET(collection, key);}
// Publish via redis.async function pub(channel, message) { try { await client.publish(channel, message); console.log("Published:", channel, message); } catch (err) { console.log("🙅♂️ Could not publish:", channel, err); } return true;}
export { connect, get, set, del, pub, disconnect };