-
Create MemoryStore for Redis deployment in GCP console
-
View the service information
gcloud redis instances describe my-redis --region=us-central1
- Make notes of the IP address along with port number
host: xx.xx.xx.xx
port: xxxx
connectMode: DIRECT_PEERING
-
By default Memorystore provides direct peering.When using the direct peering mode, Memorystore creates a VPC peering between the customer VPC network and the VPC network in the Google managed project. So you could create GCE to access the Memorystore for Redis. Please go to Memorystore networking to have more information.
-
Set up the authentication on the GCE when necessary
export GOOGLE_APPLICATION_CREDENTIALS="[PATH]"
-
Google Cloud does not provide offical Redis driver for CRUD and other data operations. But Google Cloud does provide the official driver for Memorystore management.
-
In the demo, the standard Node.js driver for Redis is used. The demo gives the basic idea how pubsub functionality works in Memorystore for Redis.
-
Prepare the node.js enviroment by using nvm, and run the demo as below.
npm install
Change pubsub.js to specify the host and port for the Memorystore for Redis
node app.js
- Also, Redis tools provide command line tools for pubsub as well.
redis-cli -h xx.xx.xx.xx -p xxxx
>publish channel:test "hello,test"
>subscribe channel:test
- The demo is originally from this github, and is changed for the demo.