Docs
Node.js
iovalkey, node-redis, Express sessions and Nuxt/Nitro storage.
Each example reads the connection URL from VALKEY_URL; copy it from your instance page in the dashboard. See connection details and limits for what applies to every client.
On this page: iovalkey · node-redis · Express sessions · Nuxt / Nitro storage
iovalkey
The Valkey fork of ioredis. A rediss:// URL turns on TLS, and Node sends the hostname as SNI automatically.
Install
npm install iovalkeyindex.mjs
import Valkey from "iovalkey"; const client = new Valkey(process.env.VALKEY_URL); await client.set("greeting", "hello", "EX", 60);console.log(await client.get("greeting")); await client.quit();node-redis
The redis package works with both Redis and Valkey instances. Always attach an error handler, so a dropped connection is logged and retried instead of crashing the process.
Install
npm install redisindex.mjs
import { createClient } from "redis"; const client = createClient({ url: process.env.VALKEY_URL });client.on("error", (err) => console.error("Redis client error", err));await client.connect(); await client.set("greeting", "hello", { expiration: { type: "EX", value: 60 } });console.log(await client.get("greeting")); await client.quit();Express sessions
Store express-session data in your instance with connect-redis and node-redis.
Install
npm install express express-session connect-redis redisserver.mjs
import express from "express";import session from "express-session";import { RedisStore } from "connect-redis";import { createClient } from "redis"; const client = createClient({ url: process.env.VALKEY_URL });client.on("error", (err) => console.error("Redis client error", err));await client.connect(); const app = express();app.use(session({ store: new RedisStore({ client, prefix: "sess:" }), secret: process.env.SESSION_SECRET, resave: false, saveUninitialized: false, cookie: { secure: true, httpOnly: true, sameSite: "lax" },})); app.get("/", (req, res) => { req.session.views = (req.session.views ?? 0) + 1; res.send("Views: " + req.session.views);}); app.listen(3000);On Starter, old sessions can be evicted when memory is full, which signs those users out.
Nuxt / Nitro storage
Point a Nitro storage mount (and with it cached routes and useStorage) at your instance through the unstorage redis driver.
Install
npm install ioredisnuxt.config.ts
export default defineNuxtConfig({ nitro: { storage: { cache: { driver: "redis", url: process.env.VALKEY_URL, }, }, },});server/api/hello.get.ts
export default defineEventHandler(async () => { const storage = useStorage("cache"); await storage.setItem("greeting", "hello"); return { greeting: await storage.getItem("greeting") };});