How to create a Redis database and connect it to your application?
1. Prerequisites
To follow this tutorial, you will need:
- Standard Plan or higher: Redis database management is a feature available starting from the Standard plan.
- Dashboard Access: Your login credentials for the Square Cloud platform.
2. Creating the Database Instance
- Access the Square Cloud Dashboard.
- Go to the Databases page and select the Create database option.
- Name your instance.
- Choose Redis from the list of available databases.
- Select the desired RAM and confirm the creation.
- After initialization, you will have access to the essential credentials in a URL:
Host,Port,Password.
3. Understanding SSL Certificates
Square Cloud requires encrypted connections (TLS/SSL) to protect data transmitted in memory. To establish this connection, you will need to use the certificates provided by the platform.
In your database settings tab, you will find the following download options:
certificate.pem: This is a combined file containing the private key (key) and the certificate (cert). For most connection drivers, this is the only required file.client-key.keyandclient-cert.crt: Available separately for legacy systems or drivers that require individual files.
4. Technical Connection Configuration
For Redis, a secure connection is identified by the rediss:// protocol (with two "s"s). When configuring the driver, you must point to the .pem file to validate the identity of both the client and the server.
Technical parameters generally follow this mapping when using the .pem file:
- ssl_ca_certs: Path to
certificate.pem - ssl_certfile: Path to
certificate.pem - ssl_keyfile: Path to
certificate.pem
Connection String Example (URI)
rediss://default:{password}@square-cloud-db-{id}.squareweb.app:{port}?ssl_ca_certs=./certificate.pem&ssl_certfile=./certificate.pem&ssl_keyfile=./certificate.pemConnection Examples via Code
If your connection uses the separate files, simply follow the examples below:
- Python Example:
import redis
import os
import ssl
from pathlib import Path
ca_cert_path = Path(__file__).with_name("ca-certificate.crt")
r = redis.from_url(
"rediss://default:JTI6bNRaws1Z1jokWU8mRfoW@square-cloud-db-{id}.squareweb.app:{port}",
decode_responses=True,
ssl_cert_reqs=ssl.CERT_REQUIRED,
ssl_ca_certs=str(ca_cert_path)
)
- JavaScript Example:
import { createClient } from "redis";
import fs from "fs";
const client = createClient({
url: "rediss://default:JTI6bNRaws1Z1jokWU8mRfoW@square-cloud-db-{id}.squareweb.app:{port}",
socket: {
tls: true,
ca: fs.readFileSync("ca-certificate.crt")
},
});
async function main() {
await client.connect();
console.log("Connected to Redis!");
}
main()
5. Best Practices and Security
- .gitignore File: The
certificate.pemfile contains sensitive information. Never upload it to public repositories; add it to your.gitignoreimmediately. - Secure Protocol: Always ensure you use the
rediss://prefix instead ofredis://to guarantee that the driver attempts to perform the SSL handshake.
Extra
For a better visual guide, watch our video tutorial: https://www.youtube.com/watch?v=WJsgRKsQrCI
Updated on: 05/21/2026
Thank you!
