Conéctate a una instancia de Memorystore for Redis Cluster
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
En esta página, se explica cómo conectarse a una instancia de Memorystore para Redis Cluster.
Asistencia al cliente
Memorystore para Redis Cluster no proporciona sus propias bibliotecas cliente, sino que admite las bibliotecas cliente de terceros existentes que admiten el protocolo de Redis.
Puedes encontrar una lista de ejemplo de clientes en la página Clientes de Redis.
Prácticas recomendadas del cliente de redis-py
Para conectarte a tu instancia de Memorystore for Redis Cluster con el cliente de Python redis-py, debes agregar skip_full_coverage_check=True cuando declares un clúster de Redis:
Si no incluyes los puertos correctos en la lista de entidades permitidas de tu firewall, es posible que tu instancia tenga errores de conexión. Para obtener más información sobre cómo incluir puertos en la lista de entidades permitidas, consulta Soluciona problemas.
Acceso entre regiones
Puedes acceder a una instancia de Memorystore for Redis Cluster desde un cliente ubicado en una región diferente a la de la instancia de Memorystore.
Consulta el extremo de detección de tu clúster
Para ver el extremo de detección de tu clúster de Memorystore, sigue estas instrucciones:
Console
Ve a la página Memorystore for Redis Cluster en la Google Cloud consola.
En la sección Conéctate a esta instancia, anota la dirección IP y el número de puerto junto a Extremo de detección. Estos dos valores juntos son el extremo de detección de tu clúster.
gcloud
Para ver el extremo de descubrimiento de tu clúster, ejecuta la CLI de describe gcloud como se explica en la sección Consulta los detalles de la instancia.
El resultado debería ser similar al siguiente ejemplo:
Toma nota de la dirección del extremo y el número de puerto que se indican en la sección discovery_endpoints:. Estos dos valores juntos son el extremo de detección de tu clúster.
Conéctate desde una VM de Compute Engine con redis-cli
Puedes conectarte a la instancia de Memorystore for Redis Cluster desde cualquier VM de Compute Engine que use la red autorizada de la instancia de Memorystore.
Para conectarte a la instancia, sigue estos pasos:
Si aún no tienes una VM de Compute Engine de Linux que use la red autorizada para tu instancia de Memorystore para Redis Cluster, crea una y conéctate a ella siguiendo la Guía de inicio rápido para crear una VM de Linux.
Instala la versión redis-cli 6.0 o posterior en la VM de Compute Engine siguiendo las instrucciones en Cómo instalar Redis en Linux.
DISCOVERY_ENDPOINT_ADDRESS y PORT_NUMBER son los valores que anotaste en el paso anterior.
Ejecuta el comando CLUSTER SHARDS para ver la topología del clúster. Anota una de las direcciones IP y los números de puerto del nodo.
Conéctate al nodo que desees ejecutando el siguiente comando:
redis-cli -h NODE_IP_ADDRESS -p NODE_PORT -c
Reemplaza lo siguiente:
NODE_IP_ADDRESS es la dirección IP del nodo que encontraste en el paso anterior.
NODE_PORT es el número de puerto del nodo que encontraste en el paso anterior.
Una vez que te conectes al nodo, ingresa algunos comandos de Redis:
Escribe lo siguiente:
PING
Resultado:
PONG
Ingresa:
SET HELLO WORLD
Resultado:
OK
Ingrese:
GET HELLO
Resultado:
"WORLD"
Una vez que termines de probar tu conexión con el nodo de Redis, debes considerar borrar la VM de Compute Engine que usaste para conectarte a la instancia de Redis. Esto te ayuda a evitar que se generen cargos en tu cuenta de Facturación de Cloud.
Conéctate a una instancia habilitada para la encriptación en tránsito
En esta sección, se proporciona un ejemplo de cómo conectarse a una instancia de Memorystore for Redis Cluster que tiene habilitada la encriptación en tránsito.
Si aún no tienes una VM de Compute Engine que use la misma red autorizada que la instancia de Redis del paso anterior, crea una y conéctate a ella siguiendo la Guía de inicio rápido sobre el uso de una VM de Linux.
Instala la versión 6.0 o posterior de redis-cli en la VM de Compute Engine siguiendo las instrucciones que se indican en Cómo instalar Redis en Linux.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 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 ```"]]