Connect to a Redis cluster
A Redis cluster can be connected to:
- through Docker;
- program code with and without SSL.
Connection with SSL certificate is available for all methods.
Specify the port and address when connecting.
Connection ports
Use ports to connect to Redis:
- 6380 — port for connection with SSL certificate;
- 6379 — port for connection without SSL certificate (available only for clusters in private subnet).
Addresses for connection
The address to connect to depends on the cluster subnet and where you are connecting from. You can choose an address depending on one of the scenarios:
- connecting to a cluster on a public subnet;
- connect from a private subnet to a cluster on a private subnet;
- connecting from the Internet to a cluster on a private subnet.

Connecting to a cluster on a public subnet
If the cluster is on a public subnet, the nodes can be connected to by DNS address or IP address from the public subnet.
We recommend connecting by DNS address. For DNS addresses in the cluster, the master discovery mechanism is used — the address is bound to the node role, not to the node itself. If the master is unavailable, one of the replicas becomes the new master and the address is transferred to the new node along with the role.
When connecting using an IP address from a public subnet, the master discovery mechanism is not used. If one of the replicas becomes the new master, the master IP address will change and the connection to the old IP address will not work.
You can view the address to connect to in the control panel.
Connecting from a private subnet to a cluster on a private subnet
If you are connecting from a private subnet to a cluster on a private subnet, you can use a DNS address or a private IP address.
We recommend connecting by DNS address. For DNS addresses in the cluster, the master discovery mechanism is used — the address is bound to the node role, not to the node itself. If the master is unavailable, one of the replicas becomes the new master and the address is transferred to the new node along with the role.
When connecting by private IP address, the master discovery mechanism is not used. If one of the replicas becomes the new master, the master IP address will change and the connection using the old IP address will not work.
To connect from another private subnet, first connect both private subnets to the cloud router.
You can view the address to connect to in the control panel.
Connecting from the Internet to a cluster on a private subnet
Если вы подключаетесь к кластеру в приватной подсети из интернета, можно использовать только публичный IP-адрес (Floating IP). Приватная подсеть должна соответствовать требованиям. Если подсеть не соответствует требованиям, подготовьте ее для подключения публичного IP-адреса (Floating IP).
For public IP addresses (Floating IPs) the master discovery mechanism is used — the address is bound to the role of the node, not to the node itself. If the master is unavailable, one of the replicas becomes the new master and the address is transferred to the new node along with the role.
You can view the address to connect to in the control panel.
View the address for connection
- In the Dashboard, on the top menu, click Products and select Cloud Databases.
- Open the Active tab.
- Open the Database Cluster page → Connection tab.
- In the Addresses to connect block, look up the address.
Connect with SSL
Connecting using TLS(SSL)-encryption provides a secure connection between your server and the database cluster.
Bash
PowerShell
Python
PHP
Go
Node.js
-
Download the root certificate and place it in the
~/.redis/folder:mkdir -p ~/.redis/
wget https://storage.dbaas.selcloud.ru/CA.pem -O ~/.redis/root.crt
chmod 600 ~/.redis/root.crt -
Connect to the cluster:
redis-cli -h <host> \
-a <password> \
-p <port> \
--tls \
--cacert ~/.redis/root.crtSpecify:
<host>— DNS address or public IP address (Floating IP) of the node;<password>— password;<port>— port for connection.
-
In the control panel, click Download Certificate to download the root certificate and place it in the
%APPDATA%\redis\folder. -
Connect to the cluster:
redis-cli -h <host> `
-a <password> `
-p <port> `
--tls `
--cacert %APPDATA%\redis\CA.pemSpecify:
<host>— DNS address or public IP address (Floating IP) of the node;<password>— password;<port>— port for connection.
-
Download the root certificate and place it in the
~/.redis/folder:mkdir -p ~/.redis/
wget https://storage.dbaas.selcloud.ru/CA.pem -O ~/.redis/root.crt
chmod 600 ~/.redis/root.crt -
Install the redis library:
pip install redis -
Use the connection example:
import redis
r = redis.Redis(
host="<host>",
password="<password>",
port=<port>,
db=0,
ssl=True,
ssl_ca_certs="<path>",
)
print(r.set("KEY", "VALUE"))
print(r.get("KEY"))Specify:
<host>— DNS address or public IP address (Floating IP) of the node;<password>— user password;<port>— port for connection;<path>— the full path to the root certificate.
-
Download the root certificate and place it in the
~/.redis/folder:mkdir -p ~/.redis/
wget https://storage.dbaas.selcloud.ru/CA.pem -O ~/.redis/root.crt
chmod 600 ~/.redis/root.crt -
Install the predis library via composer:
composer require predis/predis -
Use the connection example:
<?php
require __DIR__ . '/vendor/autoload.php';
Predis\Autoloader::register();
$host = ['<host>:<port>'];
$options = [
'parameters' => [
'scheme' => 'tls',
'ssl' => ['cafile' => '<path>', 'verify_peer' => true],
'password' => "<password>"
],
'cluster' => 'predis'
];
$conn = new Predis\Client($host, $options);
$conn->set('KEY', 'VALUE');
var_dump($conn->get('KEY'));
$conn->disconnect();
?>Specify:
<host>— DNS address or public IP address (Floating IP) of the node;<port>— port for connection;<path>— the full path to the root certificate;<password>— user password.
-
Download the root certificate and place it in the
~/.redis/folder:mkdir -p ~/.redis/
wget https://storage.dbaas.selcloud.ru/CA.pem -O ~/.redis/root.crt
chmod 600 ~/.redis/root.crt -
Use the connection example:
package main
import (
"context"
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"github.com/go-redis/redis/v8"
)
var ctx = context.Background()
var certPath = "<path>"
func main() {
caCert, err := ioutil.ReadFile(certPath)
if err != nil {
panic(err)
}
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)
rdb := redis.NewClient(&redis.Options{
Addr: "<host>:<port>",
Password: "<password>",
DB: 0,
TLSConfig: &tls.Config{
RootCAs: caCertPool,
InsecureSkipVerify: true,
},
})
err = rdb.Set(ctx, "key", "value", 0).Err()
if err != nil {
panic(err)
}
val, err := rdb.Get(ctx, "key").Result()
if err != nil {
panic(err)
}
fmt.Println("key", val)
}Specify:
<path>— the full path to the root certificate;<host>— DNS address or public IP address (Floating IP) of the node;<port>— port for connection;<password>— user password.
-
Download the root certificate and place it in the
~/.redis/folder:mkdir -p ~/.redis/
wget https://storage.dbaas.selcloud.ru/CA.pem -O ~/.redis/root.crt
chmod 600 ~/.redis/root.crt -
Install the ioredis client:
npm install ioredis -
Use the connection example:
const fs = require('fs');
const Redis = require('ioredis');
const config = {
host: '<host>',
port: <port>,
password: '<password>',
tls: {
rejectUnauthorized: true,
ca: fs.readFileSync('<path>').toString(),
}
};
const connection = new Redis(config);
connection.set('key', 'value', (error) => {
if (error) throw error;
});
connection.get('key', (error, res) => {
if (error) throw error;
console.log(res);
connection.disconnect();
});Specify:
<host>— DNS address or public IP address (Floating IP) of the node;<port>— port for connection;<password>— user password;<path>— the full path to the root certificate.
Connect without SSL
Connection without SSL is only available for clusters on a private subnet.
Bash
PowerShell
Python
PHP
Go
Node.js
-
Open the CLI.
-
Connect to the cluster:
redis-cli -h <host> \
-a <password> \
-p <port>Specify:
<host>— DNS address or public IP address (Floating IP) of the node;<password>— password;<port>— port for connection.
-
Open the CLI.
-
Connect to the cluster:
redis-cli -h <host> `
-a <password> `
-p <port>Specify:
<host>— DNS address or public IP address (Floating IP) of the node;<password>— password;<port>— port for connection.
-
Install the redis library:
pip install redis -
Use the connection example:
import redis
r = redis.Redis(
host="<host>",
password=r"<password>",
port=<port>,
db=0,
)
print(r.set("KEY", "VALUE"))
print(r.get("KEY"))Specify:
<host>— DNS address or public IP address (Floating IP) of the node;<password>— user password;<port>— port for connection.
-
Install the predis library via composer:
composer require predis/predis -
Use the connection example:
<?php
require __DIR__ . '/vendor/autoload.php';
Predis\Autoloader::register();
$host = ['<host>:<port>'];
$options = [
'parameters' => [
'password' => "<password>"
],
'cluster' => 'predis'
];
$conn = new Predis\Client($host, $options);
$conn->set('KEY', 'VALUE');
var_dump($conn->get('KEY'));
$conn->disconnect();
?>Specify:
<host>— DNS address or public IP address (Floating IP) of the node;<port>— port for connection;<password>— user password.
Use the connection example:
package main
import (
"context"
"fmt"
"github.com/go-redis/redis/v8"
)
func main() {
var ctx = context.Background()
rdb := redis.NewClient(&redis.Options{
Addr: "<host>:<port>",
Password: "<password>",
DB: 0,
})
err := rdb.Set(ctx, "key", "value", 0).Err()
if err != nil {
panic(err)
}
val, err := rdb.Get(ctx, "key").Result()
if err != nil {
panic(err)
}
fmt.Println("key", val)
}
Specify:
<host>— DNS address or public IP address (Floating IP) of the node;<port>— port for connection;<password>— user password.
-
Install the ioredis client:
npm install ioredis -
Use the connection example:
const Redis = require('ioredis');
const config = {
host: '<host>',
port: <port>,
password: '<password>',
};
const connection = new Redis(config);
connection.set('key', 'value', (error) => {
if (error) throw error;
});
connection.get('key', (error, res) => {
if (error) throw error;
console.log(res);
connection.disconnect();
});Specify:
<host>— DNS address or public IP address (Floating IP) of the node;<port>— port for connection;<password>— user password.
Connect via Docker
-
Download the root certificate and place it in the
~/.redis/folder:mkdir -p ~/.redis/
wget https://storage.dbaas.selcloud.ru/CA.pem -O ~/.redis/root.crt
chmod 600 ~/.redis/root.crt -
Connect to the cluster:
docker run --rm -it \
-v $(pwd)/.redis/root.crt:/root.crt \
redis \
redis-cli \
-h <host> \
-a <password> \
-p <port> --tls \
--cacert /root.crtSpecify:
<host>— DNS address or public IP address (Floating IP) of the node;<password>— user password;<port>— port for connection.