-->

DEVOPSZONES

  • Recent blogs

    How to Connect to a Redis instance from a Compute Engine VM in google Cloud

     There are multiple options to connect to a redis instance in GCP (Google Cloud Project) to test.

    1. Telnet
    2. GKE
    3. redis-cli

    Telnet:

    1. Create a Compute Engine VM that uses that same authorized network as your Redis instance.

    2. Install telnet using apt-get:

    1. sudo apt-get install telnet
    3. From the terminal, telnet to the IP address of the Redis instance.

    1. telnet 10.21.0.4 6379
      

      If successful, the command will return this result:

      Trying 10.21.0.4…
      Connected to 10.21.0.4
      
    2. In the telnet session, enter some Redis commands:

      Enter:

      PING
      

      Result:

      PONG
      

      Enter

      SET HELLO WORLD
      

      Result:

      +OK
      

      Enter:

      GET HELLO
      

      Result:

      $5
      WORLD


    redis-cli


    1. Create a Compute Engine VM that uses that same authorized network as your Redis instance.

    1. Install redis-cli on the Compute Engine VM by running the following command from the Compute Engine SSH terminal:

      sudo apt-get install redis-tools
      
    2. Run the following command in the Compute Engine terminal, replacing variables with appropriate values.

      redis-cli -h 10.21.0.4
      

      You are now connected to your Redis instance using redis-cli.

    3. Once you are done testing your connection to the Redis instance, you should consider deleting the Compute Engine VM .


    Redis that uses auth: redis-cli -h 10.21.0.4 -a auth-string

    GKE:

    1. Go to the GKE page in the Google Cloud console.
    2.
    1. Click the Connect button to the right of your cluster's name, then click the Run in Cloud Shell button in the window that appears.
    2. Configure kubectl command line access by running the following command:
      gcloud container clusters get-credentials CLUSTER_NAME --zone=CLUSTER_ZONE --project=PROJECT_ID
      • CLUSTER_NAME is the name of your cluster.
      • CLUSTER_ZONE is the zone your cluster is in. Must also be the zone your Redis instance is in.
      • PROJECT_ID is the project where your cluster and your Redis instances exist.
      You should get the success message: kubeconfig generated for CLUSTER_NAME

    1. Use the following command to start a Redis pod running the redis-cli:
      kubectl run -i --tty redisbox --image=gcr.io/google_containers/redis:v1 -- sh
    2. Run a redis-cli command, replacing HOST-IP with the host IP address of your Redis instance:
      redis-cli -h 10.248.68.116 info
    3. Optionally, run a Redis benchmark command, again replacing HOST-IP with the host IP address of your Redis instance:
      redis-benchmark -c 100 -n 100000 -d 1024 -r 100000 -t PING,SET,GET,INCR,LPUSH,RPUSH,LPOP,RPOP,SADD,SPOP,MSET -h 10.248.68.116

    Thanks.



    No comments