Skip to documentation
Documentation menu · Connect to Redis

Redis

Connect to Redis

Copy the correct endpoint and credentials, then connect from your server-side code.

On this page

Connection fields

Open Redis > Connection and copy Host, Port, Username and Password. Use the actual username shown, commonly default, and the password for this database. All values in the example are placeholders.

Products in the same DLEZ organization communicate through private endpoints, including products in different projects. Use the destination service's private host and port. Your laptop and browser are external clients even when you are signed in to Console; use a public endpoint for external access. Keep credentials on the server and follow the service's TLS requirements.

REDIS_HOST="copy-host-from-console"
REDIS_PORT="copy-port-from-console"
REDIS_USERNAME="copy-from-console"
REDIS_PASSWORD="copy-from-console"

Node.js

Install redis with npm install redis. Use these connection settings in server-side code and add TLS settings if required by the endpoint. Handle connection errors in your app and close the client when it is no longer needed.

import { createClient } from "redis";
const client = createClient({
  username: process.env.REDIS_USERNAME,
  password: process.env.REDIS_PASSWORD,
  socket: {
    host: process.env.REDIS_HOST,
    port: Number(process.env.REDIS_PORT),
  },
});
client.on("error", (error) => console.error(error.message));
await client.connect();
await client.set("docs:hello", "dlez", { EX: 60 });
console.log(await client.get("docs:hello"));
await client.quit();

Go

Install github.com/redis/go-redis/v9. This configuration excerpt assumes the os and redis packages are imported. Configure TLS when required, execute a test operation and handle returned errors.

rdb := redis.NewClient(&redis.Options{
    Addr: os.Getenv("REDIS_HOST") + ":" + os.Getenv("REDIS_PORT"),
    Username: os.Getenv("REDIS_USERNAME"),
    Password: os.Getenv("REDIS_PASSWORD"),
})