# Connecting with redis-cli

This guide explains how to establish a connection between <span class="s3">redis-cli</span> and a Redis database instance. It walks through the necessary setup, configuration, and execution of a simple Redis command from the terminal.

## **Variables**

Certain parameters must be provided to establish a successful connection to a Redis database. Below is a breakdown of each required variable, its purpose, and where to find it. Here’s what each variable represents:

<table border="1" id="bkmrk-variable-description" style="width: 100%; border-collapse: collapse; border-color: rgb(0, 0, 0);"><thead><tr><th style="width: 12.1573%; border-color: rgb(0, 0, 0);">**Variable**

</th><th style="width: 41.8355%; border-color: rgb(0, 0, 0);">**Description**

</th><th style="width: 46.1263%; border-color: rgb(0, 0, 0);">**Purpose**

</th></tr></thead><tbody><tr><td style="width: 12.1573%; border-color: rgb(0, 0, 0);">`HOST`

</td><td style="width: 41.8355%; border-color: rgb(0, 0, 0);">Redis hostname, from the Elestio service overview page

</td><td style="width: 46.1263%; border-color: rgb(0, 0, 0);">The address of the server hosting your Redis instance.

</td></tr><tr><td style="width: 12.1573%; border-color: rgb(0, 0, 0);">`PORT`

</td><td style="width: 41.8355%; border-color: rgb(0, 0, 0);">Port for Redis connection, from the Elestio service overview page

</td><td style="width: 46.1263%; border-color: rgb(0, 0, 0);">The network port used to connect to Redis. The default port is 6379.

</td></tr><tr><td style="width: 12.1573%; border-color: rgb(0, 0, 0);">`PASSWORD`

</td><td style="width: 41.8355%; border-color: rgb(0, 0, 0);">Redis password, from the Elestio service overview page

</td><td style="width: 46.1263%; border-color: rgb(0, 0, 0);">The authentication key required to connect securely to Redis.

</td></tr></tbody></table>

These values can usually be found in the Elestio service overview details as shown in the image below, make sure to take a copy of these details and use them in the command moving ahead.

[![Screenshot 2025-05-19 at 12.23.05 PM.jpg](https://docs.elest.io/uploads/images/gallery/2025-05/scaled-1680-/screenshot-2025-05-19-at-12-23-05-pm.jpg)](https://docs.elest.io/uploads/images/gallery/2025-05/screenshot-2025-05-19-at-12-23-05-pm.jpg)

## **Prerequisites**

**Install redis-cli**

Check if <span class="s2">redis-cli</span> is installed by running:

```
redis-cli --version
```

If not installed, you can install it via:

- **macOS**<span class="s1">:</span>

```
brew install redis
```

- **Ubuntu/Debian**<span class="s1">:</span>

```
sudo apt install redis-tools
```

- **Windows**<span class="s1">:</span>
    
    Use Windows Subsystem for Linux (WSL) or download a Redis CLI binary.

## **Command**

Once all prerequisites are set up, open the terminal or command prompt and run the following command:

```bash
redis-cli -h HOST -p PORT -a PASSWORD
```

Replace <span class="s1">HOST</span>, <span class="s1">PORT</span>, and <span class="s1">PASSWORD</span> with the actual values from your Elestio Redis service. If the connection is successful, the terminal will display a Redis prompt like this:

```
HOST:PORT>
```

You can then run a simple command to test the connection:

```
set testKey "Hello Redis"
get testKey
```

Expected output:

```
"Hello Redis"
```

If the connection is successful, the terminal will display output similar to:

```
"Hello Redis"
```