Menghubungkan ke instance Memorystore for Redis Cluster
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Halaman ini menjelaskan cara terhubung ke instance Memorystore for Redis Cluster.
Dukungan klien
Memorystore for Redis Cluster tidak menyediakan library kliennya sendiri, tetapi mendukung library klien pihak ketiga yang ada yang mendukung protokol Redis.
Contoh daftar klien dapat ditemukan di halaman Klien Redis.
Praktik terbaik klien Redis-py
Untuk terhubung ke instance Memorystore for Redis Cluster menggunakan klien Python redis-py, Anda harus menambahkan skip_full_coverage_check=True saat mendeklarasikan Redis Cluster:
Mengizinkan port dalam daftar yang diizinkan di firewall
Jika Anda tidak memasukkan port yang benar ke dalam daftar yang diizinkan di firewall, instance Anda dapat mengalami error koneksi. Untuk mengetahui informasi selengkapnya tentang cara memasukkan port ke daftar yang diizinkan, lihat
Memecahkan masalah.
Akses lintas region
Anda dapat mengakses instance Memorystore for Redis Cluster dari klien yang berada di
region yang berbeda dengan lokasi instance Memorystore.
Melihat endpoint penemuan cluster Anda
Untuk melihat endpoint penemuan cluster Memorystore Anda, gunakan petunjuk berikut:
Konsol
Buka halaman Memorystore for Redis Cluster di konsol Google Cloud .
Di bagian Connect to this instance, catat alamat IP dan nomor port di samping Discovery Endpoint. Kedua nilai yang digunakan bersama ini adalah endpoint penemuan cluster Anda.
gcloud
Untuk melihat endpoint penemuan cluster Anda, jalankan describe
gcloud CLI seperti yang dijelaskan di bagian melihat detail instance.
Catat alamat endpoint dan nomor port yang tercantum di bagian
discovery_endpoints:. Kedua nilai ini yang digunakan bersama adalah endpoint penemuan cluster Anda.
Menghubungkan dari VM Compute Engine menggunakan redis-cli
Anda dapat terhubung ke instance Memorystore for Redis Cluster dari VM Compute Engine mana pun yang menggunakan jaringan resmi instance Memorystore.
Untuk terhubung ke instance:
Jika Anda belum memiliki VM Compute Engine Linux yang menggunakan
jaringan yang diizinkan untuk instance Memorystore for Redis Cluster, buat VM dan
hubungkan ke VM tersebut dengan mengikuti Panduan memulai untuk membuat VM Linux.
Instal redis-cli versi 6.0 atau yang lebih baru di VM Compute Engine dengan
mengikuti petunjuk di Menginstal Redis di Linux.
DISCOVERY_ENDPOINT_ADDRESS dan PORT_NUMBER
adalah nilai yang Anda catat di langkah sebelumnya.
Jalankan perintah CLUSTER SHARDS untuk melihat topologi cluster Anda. Catat salah satu alamat IP dan nomor port node.
Hubungkan ke node yang diinginkan dengan menjalankan perintah berikut:
redis-cli -h NODE_IP_ADDRESS -p NODE_PORT -c
Ganti kode berikut:
NODE_IP_ADDRESS adalah alamat IP node yang Anda temukan di
langkah sebelumnya.
NODE_PORT adalah nomor port node yang Anda temukan di langkah sebelumnya.
Setelah terhubung ke node, masukkan beberapa perintah Redis:
Enter:
PING
Hasil:
PONG
Enter
SET HELLO WORLD
Hasil:
OK
Enter:
GET HELLO
Hasil:
"WORLD"
Setelah selesai menguji koneksi ke node Redis, Anda harus mempertimbangkan untuk menghapus VM Compute Engine yang Anda gunakan untuk terhubung ke instance Redis. Tindakan ini membantu Anda menghindari biaya yang ditagihkan ke akun Penagihan Cloud Anda.
Menghubungkan ke instance yang mendukung enkripsi saat transit
Bagian ini memberikan contoh cara terhubung ke instance Memorystore for Redis Cluster yang mengaktifkan enkripsi saat transit.
Jika Anda belum memiliki VM Compute Engine yang menggunakan jaringan resmi yang sama dengan instance Redis dari langkah sebelumnya, buat VM dan hubungkan dengan mengikuti Panduan memulai menggunakan VM Linux.
Instal redis-cli versi 6.0 atau yang lebih baru di VM Compute Engine
dengan mengikuti petunjuk di Menginstal Redis di Linux.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-09-04 UTC."],[],[],null,["# Connect to a Memorystore for Redis Cluster instance\n\nThis page explains how to connect to a Memorystore for Redis Cluster instance.\n\nClient support\n--------------\n\nMemorystore for Redis Cluster does not provide its own client libraries, but rather\nsupports existing third-party client libraries that support the Redis protocol.\nAn example list of clients can be found on the Redis [Clients](https://redis.io/docs/clients/)\npage.\n\n### Redis-py client best practice\n\nTo connect to your Memorystore for Redis Cluster instance using the [redis-py](https://github.com/redis/) Python client, you must add the `skip_full_coverage_check=True` when declaring a Redis\nCluster: \n\n from rediscluster import RedisCluster\n endpoints = [{\"host\": \"IPADDRESS\", \"port\": \"6379\"}]\n\n rdb = RedisCluster(\n startup_nodes=endpoints,\n skip_full_coverage_check=True, # Required for Memorystore\n decode_responses = True)\n\n print(rdb.set('PYTHON', 'CLUSTER'))\n print(rdb.get('PYTHON'))\n print(rdb.unlink('PYTHON'))\n\nAllowlist ports on firewall\n---------------------------\n\nIf you don't allowlist the correct ports on your firewall, your instance can\nencounter connection errors. For more information about allowlisting ports, see\n[Troubleshoot issues](/memorystore/docs/cluster/troubleshoot-issues#connection_error_caused_by_firewall_rules).\n\nCross region access\n-------------------\n\nYou can access a Memorystore for Redis Cluster instance from a client located in a\ndifferent region than where the Memorystore instance is located.\n\nView your cluster's discovery endpoint\n--------------------------------------\n\nTo view your Memorystore cluster's [discovery endpoint](/memorystore/docs/cluster/overview#discovery_endpoint), use the following instructions: \n\n### Console\n\n1. Go to the **Memorystore for Redis Cluster** page in the Google Cloud console.\n\n [Memorystore for Redis Cluster](https://console.cloud.google.com/memorystore/redis/clusters?)\n2. Click your Cluster ID.\n\n3. In the **Connect to this instance** section, take a note of the IP address\n and port number next to **Discovery Endpoint**. These two values used\n together are your cluster's discovery endpoint.\n\n### gcloud\n\nTo view your cluster's discovery endpoint, run the `describe`\ngcloud CLI as explained in the [view instance details](/memorystore/docs/cluster/create-manage-instances#view_instance_details) section.\n\nThe output should be similar to the following: \n\n authorizationMode: AUTH_MODE_DISABLED\n createTime: '2023-08-04T17:49:07.988918793Z'\n discoveryEndpoints:\n - address: 10.142.0.13\n port: 6379\n pscConfig:\n - network: projects/my-project-364018/global/networks/default\n name: projects/my-project-364018/locations/us-east1/clusters/my-cluster-1\n pscConnections:\n - address: 10.142.0.13\n forwardingRule: https://www.googleapis.com/compute/v1/projects/my-project-364018/regions/us-east1/forwardingRules/sca-auto-fr-5bc46f69-ec80-4c5a-8971-ce267a4d8ddd\n network: projects/my-project-364018/global/networks/default\n projectId: my-project-364018\n pscConnectionId: '25734306048376845'\n - address: 10.142.0.10\n forwardingRule: https://www.googleapis.com/compute/v1/projects/my-project-364018/regions/us-east1/.\n forwardingRules/sca-auto-fr-817b64c5-85ac-48d0-82e3-c6fa99b4e67d\n network: projects/my-project-364018/global/networks/default\n projectId: my-project-364018\n pscConnectionId: '25734306048376842'\n replicaCount: 0\n shardCount: 3\n sizeGb: 39\n state: ACTIVE\n tier: PERFORMANCE\n transitEncryptionMode: TRANSIT_ENCRYPTION_MODE_DISABLED\n uid: cddda5de-d91f-449b-8755-3a665430271a\n\nTake a note of the endpoint address and port number listed in the\n`discovery_endpoints:` section. These two values used together are your\ncluster's discovery endpoint.\n\nConnect from a Compute Engine VM using redis-cli\n------------------------------------------------\n\nYou can connect to the Memorystore for Redis Cluster instance from any\nCompute Engine VM that uses the Memorystore instance's\nauthorized network.\n\nTo connect to the instance:\n\n1. If you don't already have a Linux Compute Engine VM that uses the\n authorized network for your Memorystore for Redis Cluster instance, create one and\n connect to it by following [Quickstart to create a Linux VM](/compute/docs/create-linux-vm-instance).\n\n2. Install `redis-cli` version 6.0 or newer on the Compute Engine VM by\n following the instructions at [Install Redis on Linux](https://redis.io/docs/getting-started/installation/install-redis-on-linux/).\n\n3. [View your cluster's discovery endpoint](/memorystore/docs/cluster/connect-cluster-instance#view_your_clusters_discovery_endpoint)\n and make a note of it.\n\n4. Connect to your instance's discovery endpoint by running the following\n command:\n\n ```\n redis-cli -h DISCOVERY_ENDPOINT_ADDRESS -p PORT_NUMBER -c\n ```\n\n Where:\n - \u003cvar translate=\"no\"\u003eDISCOVERY_ENDPOINT_ADDRESS\u003c/var\u003e and \u003cvar translate=\"no\"\u003ePORT_NUMBER\u003c/var\u003e are the values you noted in the previous step.\n\n | **Note:** The `-c` switch is used to enable the `redis-cli` cluster support mode. If the `-c` switch is not provided, when you try to access keys from a different shard than the one you are connected to, it results in a `MOVED` error. In the cluster support mode the client is automatically reconnected to the address returned in the error response. For more details, see [Using Redis-CLI with a Redis Cluster](https://developer.redis.com/operate/redis-at-scale/scalability/redis-cli-with-redis-cluster/).\n5. Run the `CLUSTER SHARDS` command to view your cluster topology. Take a note\n of one of the node's IP addresses and port numbers.\n\n6. Connect to your desired node by running the following command:\n\n ```\n redis-cli -h NODE_IP_ADDRESS -p NODE_PORT -c\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eNODE_IP_ADDRESS\u003c/var\u003e is the node's IP address you found in the previous step.\n - \u003cvar translate=\"no\"\u003eNODE_PORT\u003c/var\u003e is the node's port number you found in the previous step.\n7. Once connected to the node, enter some Redis commands:\n\n Enter: \n\n ```\n PING\n ```\n\n Result: \n\n ```\n PONG\n ```\n\n Enter \n\n ```\n SET HELLO WORLD\n ```\n\n Result: \n\n ```\n OK\n ```\n\n Enter: \n\n ```\n GET HELLO\n ```\n\n Result: \n\n ```\n \"WORLD\"\n ```\n8. Once you are done testing your connection to the Redis node, you should\n consider deleting the Compute Engine VM you used to connect to the\n Redis instance. Doing so helps you avoid incurring charges to your\n Cloud Billing account.\n\nConnect to an in-transit encryption enabled instance\n----------------------------------------------------\n\nThis section provides an example of how to connect to a Memorystore for Redis Cluster\ninstance that has in-transit encryption enabled.\n\n1. If you don't already have a Compute Engine VM that uses the same\n authorized network as the Redis instance from the previous step, create one\n and connect to it by following [Quickstart using a Linux VM](/compute/docs/create-linux-vm-instance).\n\n 1. Install `redis-cli` version 6.0 or newer on the Compute Engine VM by following the instructions at [Install Redis on Linux](https://redis.io/docs/getting-started/installation/install-redis-on-linux/).\n2. Install your instance's certificate authority on the Linux VM by following\n the instructions at [Install certificate authorities on your client](https://cloud.google.com/memorystore/docs/cluster/manage-in-transit-encryption#install_certificate_authorities_on_your_client).\n\n3. [View your cluster's discovery endpoint](/memorystore/docs/cluster/connect-cluster-instance#view_your_clusters_discovery_endpoint)\n and make a note of it.\n\n4. Connect to your instance's discovery endpoint by running the following\n command:\n\n ```\n redis-cli -h DISCOVERY_ENDPOINT_ADDRESS -p PORT_NUMBER -c --tls --cacert /tmp/server_ca.pem\n ```\n\n Where:\n - \u003cvar translate=\"no\"\u003eDISCOVERY_ENDPOINT_ADDRESS\u003c/var\u003e and \u003cvar translate=\"no\"\u003ePORT_NUMBER\u003c/var\u003e are the values you noted in the previous step.\n\n | **Note:** The `-c` switch is used to enable the `redis-cli` cluster support mode. If the `-c` switch is not provided, when you try to access keys from a different shard than the one you are connected to, it results in a `MOVED` error. In the cluster support mode the client is automatically reconnected to the address returned in the error response. For more details, see [Using Redis-CLI with a Redis Cluster](https://developer.redis.com/operate/redis-at-scale/scalability/redis-cli-with-redis-cluster/).\n5. Run the `CLUSTER SHARDS` command to view your cluster topology. Take a note\n of one of the node's IP addresses and port numbers.\n\n6. Connect to your desired node by running the following command:\n\n ```\n redis-cli -h NODE_IP_ADDRESS -p NODE_PORT -c --tls --cacert /tmp/server_ca.pem\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eNODE_IP_ADDRESS\u003c/var\u003e is the node's IP address you found in the previous step.\n - \u003cvar translate=\"no\"\u003eNODE_PORT\u003c/var\u003e is the node's port number you found in the previous step.\n7. Once connected to the node, enter some Redis commands:\n\n Enter: \n\n ```\n PING\n ```\n\n Result: \n\n ```\n PONG\n ```"]]