Connect to a Memorystore for Valkey instance

This page explains how to connect to a Memorystore for Valkey instance.

Client support

For examples and guidance on which connecting clients to use, see Client library code samples. .

Cross region access

You can access a Memorystore for Valkey instance from a client located in a different region than where the instance is located.

View your instance's discovery endpoint

To view your instance's discovery endpoint, use the following instructions:

gcloud

To view your instance's discovery endpoint, run the describe gcloud CLI as explained in view instance information.

The output should be similar to the following:

--location=us-central1 \
authorizationMode: AUTH_DISABLED
createTime: '2024-08-06T22:02:55.224704101Z'
deletionProtectionEnabled: false
discoveryEndpoints:
- address: 10.128.0.58
  network: projects/my-project/global/networks/default
  port: 6379
engineVersion: VALKEY_7_2
name: projects/myproject/locations/us-central1/instances/my-instance
nodeConfig:
  sizeGb: 6.5
nodeType: STANDARD_SMALL
persistenceConfig:
  mode: DISABLED
pscAutoConnections:
- forwardingRule: https://www.googleapis.com/compute/v1/projects/my-project/regions/us-central1/forwardingRules/sca-auto-fr-ec00907a-3ee3-4740-8092-ae832428f8e4
  ipAddress: 10.128.0.58
  network: projects/my-project/global/networks/default
  projectId: my-project
  pscConnectionId: '38876592440606778'
- forwardingRule: https://www.googleapis.com/compute/v1/projects/my-project/regions/us-central1/forwardingRules/sca-auto-fr-5ce5518f-1c59-4b46-aa74-799fad70d7b1
  ipAddress: 10.128.0.59
  network: projects/my-project/global/networks/default
  projectId: my-project
  pscConnectionId: '38876592440606779'
replicaCount: 2
shardCount: 5
state: ACTIVE
transitEncryptionMode: TRANSIT_ENCRYPTION_DISABLED
uid: 869f2d09-d20b-46d8-94ba-be83c48ceb54
updateTime: '2024-08-06T22:18:59.389980051Z'
zoneDistributionConfig:
  mode: MULTI_ZONE

Take a note of the endpoint address and port number listed in the discovery_endpoints: section. These two values used together are your instance's discovery endpoint.

Connect from a Compute Engine VM using valkey-cli

You can connect to the Memorystore for Valkey instance from any Compute Engine VM that uses the Memorystore instance's authorized network.

To connect to the instance:

  1. If you don't already have a Linux Compute Engine VM that uses the authorized network for your Memorystore for Valkey instance, create one and connect to it by following Quickstart to create a Linux VM.

  2. Install valkey-cli on the Compute Engine VM by following the instructions at Install Valkey.

  3. View your instance's discovery endpoint and make a note of it.

  4. Connect to your instance's discovery endpoint by running the following command:

    valkey-cli -h DISCOVERY_ENDPOINT_ADDRESS -p PORT_NUMBER -c
    

    Where:

    • DISCOVERY_ENDPOINT_ADDRESS and PORT_NUMBER are the values you noted in the previous step.
  5. Run the CLUSTER SHARDS command to view your node topology. Take a note of one of the node's IP addresses and port numbers.

  6. Connect to your desired node by running the following command:

    valkey-cli -h NODE_IP_ADDRESS -p NODE_PORT -c
    

    Replace the following:

    • NODE_IP_ADDRESS is the node's IP address you found in the previous step.
    • NODE_PORT is the node's port number you found in the previous step.
  7. Once connected to the node, enter some Valkey commands:

    Enter:

    PING
    

    Result:

    PONG
    

    Enter

    SET HELLO WORLD
    

    Result:

    OK
    

    Enter:

    GET HELLO
    

    Result:

    "WORLD"
    
  8. Once you are done testing your connection to the Valkey node, you should consider deleting the Compute Engine VM you used to connect to the Valkey instance. Doing so helps you avoid incurring charges to your Cloud Billing account.

Connect to an in-transit encryption enabled instance

This section provides an example of how to connect to a Memorystore for Valkey instance that has in-transit encryption enabled.

  1. If you don't already have a Compute Engine VM that uses the same authorized network as the Valkey instance from the previous step, create one and connect to it by following Quickstart using a Linux VM.

    1. Install valkey-cli version 6.0 or newer on the Compute Engine VM by following the instructions at Install Valkey.
  2. Install your instance's certificate authority on the Linux VM by following the instructions at Install certificate authorities on your client.

  3. View your instance's discovery endpoint and make a note of it.

  4. Connect to your instance's discovery endpoint by running the following command:

    valkey-cli -h DISCOVERY_ENDPOINT_ADDRESS -p PORT_NUMBER -c --tls  --cacert /tmp/server_ca.pem
    

    Where:

    • DISCOVERY_ENDPOINT_ADDRESS and PORT_NUMBER are the values you noted in the previous step.
  5. Run the CLUSTER SHARDS command to view your node topology. Take a note of one of the node's IP addresses and port numbers.

  6. Connect to your desired node by running the following command:

    valkey-cli -h NODE_IP_ADDRESS -p NODE_PORT -c --tls  --cacert /tmp/server_ca.pem
    

    Replace the following:

    • NODE_IP_ADDRESS is the node's IP address you found in the previous step.
    • NODE_PORT is the node's port number you found in the previous step.
  7. Once connected to the node, enter some Valkey commands:

    Enter:

    PING
    

    Result:

    PONG