Connecting to an Valkey™ cluster from applications
You can connect to a Valkey™ cluster using command line tools, graphical IDEs, or Docker containers. To learn how to connect from your application code, see Code examples.
Command line tools
To see code examples with the host FQDN filled in, open the cluster page in the management console
The setup method depends on whether sharding is enabled in the cluster.
redis-cli
For Valkey™ clusters, there is support for encrypted connections on port 6380 and unencrypted connections on port 6379.
Warning
When using SSL, you can only connect to clusters with TLS support enabled.
To always connect to the master in a non-sharded cluster, use a special FQDN that always points to the master, or track the roles of all cluster hosts yourself.
-
Before connecting, install the required dependencies:
sudo apt update && sudo apt install -y redis-tools -
Connect directly to the master host:
-
In a sharded cluster:
redis-cli \ -h c-<cluster_ID>.rw.mdb.yandexcloud.net \ -a <password> -
In a non-sharded cluster:
redis-cli \ -c \ -h <FQDN_of_master_host_in_target_shard> \ -a <password>
-
-
Before connecting, install the dependencies:
Build
redis-toolswith TLS support using one of the two methods:-
From a repository
-
Add a repository:
sudo apt-add-repository ppa:redislabs/redisThe repository’s packages come pre-built with
BUILD_TLS=yes. -
Install the tool:
sudo apt update && sudo apt install -y redis-tools
-
-
Manually
Go to the directory you want to download the distribution to. Download the stable tool version, then build and install it:
wget https://download.redis.io/redis-stable.tar.gz && \ tar -xzvf redis-stable.tar.gz && \ cd redis-stable && \ make BUILD_TLS=yes && \ sudo make install && \ sudo cp ./src/redis-cli /usr/bin/
-
-
Connect directly to the master host:
-
In a sharded cluster:
redis-cli \ -h c-<cluster_ID>.rw.mdb.yandexcloud.net \ -a <password> \ -p 6380 \ --tls \ --cacert ~/.redis/YandexInternalRootCA.crt -
In a non-sharded cluster:
redis-cli \ -c \ -h <FQDN_of_master_host_in_target_shard> \ -a <password> \ -p 6380 \ --tls \ --cacert ~/.redis/YandexInternalRootCA.crt \
-
To learn how to get a host FQDN, see this guide.
Once connected to the cluster, run these commands:
SET foo bar
GET foo
If your cluster connection and test command are successful, you will see the bar string in the output.
Valkey™ Sentinel
Valkey™ Sentinel is a Valkey™ host management system that enables monitoring, notification, automatic failover, and providing clients with the current host addresses.
For non-sharded clusters, there is support for unencrypted connections on port 26379 with any Valkey™ version.
If your client application does not support connecting via Sentinel, connect directly to the master. Otherwise, use Sentinel for more reliable cluster host management:
-
Before connecting, install the required dependencies:
sudo apt update && sudo apt install -y redis-tools -
Get the master host address by using Sentinel and any Valkey™ host:
redis-cli \ -h <FQDN_of_any_Valkey™_host> \ -p 26379 \ sentinel \ get-master-addr-by-name <Valkey™_cluster_name> | head -n 1 -
Connect to the host with this address:
redis-cli \ -h <Valkey™_master_host_address> \ -a <Valkey™_password>
To learn how to get a host FQDN, see this guide.
Once connected to the cluster, run these commands:
SET foo bar
GET foo
If your cluster connection and test command are successful, you will see the bar string in the output.
For more information about Sentinel, see Replication and fault tolerance and this Valkey™ guide
Connecting from graphical IDEs
The connection was tested in the following environment:
- MacOS Big Sur 11.3.
- DBeaver Enterprise:
21.0.
You can only use graphical IDEs to connect to cluster hosts through an SSL tunnel using the VM you created. Before connecting, prepare a certificate.
To avoid connection errors, save the certificate
Connections to Valkey™ clusters are only available in DBeaver commercial editions
To connect to your cluster:
- Create a new database connection:
- In the Database menu, select New connection.
- Select Valkey™ from the DB list.
- Click Next.
- Specify the connection settings on the Main tab:
- Host: FQDN of the master host or a special FQDN always pointing to the current master host.
When connecting to a sharded cluster, specify comma-separated FQDNs of master hosts in each shard. - Port:
6379for a regular cluster, or6380for a cluster with SSL encryption enabled. - Under Authentication, enter the cluster password.
- Host: FQDN of the master host or a special FQDN always pointing to the current master host.
- On the SSH tab:
- Enable Use SSL tunnel.
- Configure the SSH tunnel:
- Host/IP: Public IP address of the VM to connect to.
- Username: Username for connecting to the VM.
- Authentication method:
Public key. - Secret key: Path to the private key file for the VM connection.
- Passphrase: Private key password.
- On the SSL tab:
- Enable Use SSL and Skip hostname validation settings.
- Under Parameters:
- Select Method: Set of certificates.
- In the Root certificate field, specify the path to the saved SSL certificate file.
- Click Test Connection .... If the connection is successful, you will see the connection status, DBMS information, and driver details.
- Click Done to save the database connection settings.
Before you connect from a Docker container
To connect to a Yandex Managed Service for Valkey™ cluster from a Docker container, add the following lines to the Dockerfile:
# Build redis-tools with TLS support manually.
RUN apt-get update && \
apt-get install make gcc libssl-dev --yes && \
wget https://download.redis.io/redis-stable.tar.gz && \
tar -xzvf redis-stable.tar.gz && \
cd redis-stable && \
make BUILD_TLS=yes MALLOC=libc && \
make install && \
cp ./src/redis-cli /usr/bin/
# Build redis-tools with TLS support manually.
RUN apt-get update && \
apt-get install wget make gcc libssl-dev --yes && \
wget https://download.redis.io/redis-stable.tar.gz && \
tar -xzvf redis-stable.tar.gz && \
cd redis-stable && \
make BUILD_TLS=yes MALLOC=libc && \
make install && \
cp ./src/redis-cli /usr/bin/ && \
# Get an SSL certificate.
mkdir --parents ~/.redis && \
wget "https://storage.yandexcloud.net/cloud-certs/CA.pem" \
--output-document ~/.redis/YandexInternalRootCA.crt && \
chmod 0655 ~/.redis/YandexInternalRootCA.crt