Port forwarding to connect to Memorystore for Redis from local machine failing

2.1k views Asked by At

I am trying to connect to my Redis instance from my from my local machine by following this guide, where you create a Compute Engine instance to use for port forwarding to the Redis instance.

I was able to create the Compute Engine instance using:
gcloud compute instances create redis-port-forward-vm --machine-type=f1-micro --zone=us-east1-d.

When I try to create an SSH tunnel that port forwards traffic through the Compute Engine VM using:
gcloud compute ssh redis-port-forward-vm --zone=us-east1-d -- -N -L 6379:REDIS_INSTANCE_IP_ADDRESS:6379.

I get the following error: channel 2: open failed: connect failed: Connection timed out.

I don't understand what could be the issue, I am able to successfully SSH into the Compute Engine instance, but port forwarding is not working.

1

There are 1 answers

0
Gellaboina Ashish On BEST ANSWER

Follow the below steps,

  1. Install redis-cli on the Compute Engine VM by running the following command from the redis-port-forward-vm SSH terminal:
    sudo apt-get install redis-server
  2. Create a Redis instance if not created already and check the port number of the Redis instance you created (it is 6379 by default but for me it was 6378).
  3. Run the following commands on your local machine terminal
    gcloud compute ssh redis-port-forward-vm --zone=us-east1-d
    redis-cli -h REDIS INSTANCE IP -p PORT NUMBER
  4. To test the connection, open a new terminal window and run the following command:
    redis-cli ping