Yandex.Cloud
  • Services
  • Why Yandex.Cloud
  • Solutions
  • Pricing
  • Documentation
  • Contact us
Get started
Yandex Managed Service for Redis
  • Getting started
  • Step-by-step instructions
    • All instructions
    • Information about existing clusters
    • Creating clusters
    • Changing cluster and database settings
    • Connecting to databases
    • Stop and start the cluster
    • Managing hosts in a cluster
    • How to manage shards
    • Managing backups
    • Changing the master
    • Deleting clusters
  • Concepts
    • Overview
    • Host classes
    • Network in Managed Service for Redis
    • Sharding
    • Backups
    • Replication and fault tolerance
    • Supported clients
    • Limitations of Managed Service for Redis
    • Service quotas and limits
  • Access management
  • Pricing policy
    • Current pricing policy
    • Archive
      • Before February 1, 2020
  • API reference
    • Authentication in the API
    • gRPC
      • Overview
      • BackupService
      • ClusterService
      • ResourcePresetService
      • OperationService
    • REST
      • Overview
      • Backup
        • Overview
        • get
        • list
      • Cluster
        • Overview
        • addHosts
        • addShard
        • backup
        • create
        • delete
        • deleteHosts
        • deleteShard
        • get
        • getShard
        • list
        • listBackups
        • listHosts
        • listLogs
        • listOperations
        • listShards
        • move
        • rebalance
        • rescheduleMaintenance
        • restore
        • start
        • startFailover
        • stop
        • streamLogs
        • update
      • ResourcePreset
        • Overview
        • get
        • list
      • Operation
        • Overview
        • get
  • Questions and answers
    • General questions
  1. Step-by-step instructions
  2. Connecting to databases

Connecting to a database in a cluster Redis

  • Connection methods
  • Connecting to databases

Connection methods

You can connect to the Redis database in two ways: directly or using Redis Sentinel.

Redis Sentinel is a Redis host management system that provides monitoring, notification, automatic failover, and reporting of up-to-date host addresses to the clients.

Not every Redis client supports connecting via Sentinel. In such cases, you can connect to the host directly. Note that you will need to track the roles of all the hosts yourself. If there is no need for a direct connection, use Sentinel for more reliable host management.

Note

Use port 26379 for host connections via Sentinel and port 6379 for direct connections.

Redis cluster hosts cannot be assigned public IPs. You can only access hosts from within their subnet.

Connecting to databases

In this example, we connect to the Redis host from a virtual machine connected to the same subnet as the host.

  1. Create a VM with a public IP in the same subnet as the Redis host.

  2. Connect to the VM via SSH.

    $ ssh <login>@<VM public IP>
    
  3. Install Redis tools on the VM using a package manager:

    Ubuntu
    CentOS
    $ sudo apt update
    $ sudo apt-get install redis
    
    $ sudo yum update
    $ sudo yum install redis
    
  4. Install a certificate for accessing the database:

    $ sudo mkdir -p /usr/local/share/ca-certificates/Yandex
    $ sudo wget "https://storage.yandexcloud.net/cloud-certs/CA.pem" -O /usr/local/share/ca-certificates/Yandex/YandexInternalRootCA.crt
    
  5. Create a variable with the host name and port and master DB name.

    $ host=$(redis-cli -h <host address> -p 26379 sentinel get-master-addr-by-name <cluster name> | head -n 1)
    
  6. Check the connection to the host:

    $ redis-cli -h $host -a <DB password> ping
    

    If the response is PONG, the connection is established successfully.

In this article:
  • Connection methods
  • Connecting to databases
Language / Region
Careers
Privacy policy
Terms of use
Brandbook
© 2021 Yandex.Cloud LLC