Connecting from Apps
Use an official client
Prefer maintained libraries over raw TCP. They handle connection pooling and reconnects.
Node.js sketch
The redis package is a common choice.
// npm install redis
import { createClient } from "redis";
const client = createClient({ url: process.env.REDIS_URL });
await client.connect();
await client.set("greeting", "hi", { EX: 60 });
console.log(await client.get("greeting"));
Python sketch
redis on PyPI is widely used.
# pip install redis
import os
import redis
r = redis.from_url(os.environ["REDIS_URL"])
r.set("greeting", "hi", ex=60)
print(r.get("greeting"))
URLs and security
Use REDIS_URL with password and TLS in hosted environments. Never expose Redis to the public internet without auth and network controls.
Comments
One comment per signed-in account. Comments are saved with this page’s URL.