> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.squarecloud.app/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# How to create a Redis database and connect (rediss)

## 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

1. Access the [Square Cloud Dashboard](https://squarecloud.app/pt-br/dashboard).
2. Go to the [Databases](https://squarecloud.app/pt-br/dashboard/databases) page and select the **Create database** option.
3. Name your instance.
4. Choose **Redis** from the list of available databases.
5. Select the desired RAM and confirm the creation.
6. 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.key`** and **`client-cert.crt`**: Available separately for legacy systems or drivers that require individual files.



## 4. How to connect (examples per client)

The connection URL uses the secure `rediss://` scheme (with two "s", which enables TLS):

```
rediss://default:YOUR_PASSWORD@HOST:PORT
```

The `certificate.pem` file (downloaded from the dashboard) validates the connection. **How you pass the certificate depends on the client** — don't put the certificate paths as parameters in the URL: that only works in `redis-py` (Python) and breaks in `node-redis`/`ioredis`.

### Node.js — node-redis (v4+)
```javascript
import { createClient } from 'redis';
import fs from 'node:fs';

const client = createClient({
  url: 'rediss://default:YOUR_PASSWORD@HOST:PORT',
  socket: { tls: true, ca: fs.readFileSync('./certificate.pem') }
});
await client.connect();
```

### Node.js — ioredis
```javascript
import Redis from 'ioredis';
import fs from 'node:fs';

const redis = new Redis({
  host: 'HOST',
  port: PORT,
  password: 'YOUR_PASSWORD',
  tls: { ca: fs.readFileSync('./certificate.pem') }
});
```

### Python — redis-py
```python
import redis

r = redis.Redis(
    host='HOST',
    port=PORT,
    password='YOUR_PASSWORD',
    ssl=True,
    ssl_ca_certs='certificate.pem'
)
```

Replace `HOST`, `PORT` and `YOUR_PASSWORD` with your database details from the dashboard.

## 5. Best Practices and Security

* **.gitignore File:** The `certificate.pem` file contains sensitive information. Never upload it to public repositories; add it to your `.gitignore` immediately.
* **Secure Protocol:** Always ensure you use the `rediss://` prefix instead of `redis://` 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