This page shows how to install client libraries for the Cloud Memorystore for Redis API so you can connect to the API with the language of your choice.
Installing the client library
C#Install the Google.Cloud.Redis.V1 package in Visual Studio
go get -u cloud.google.com/go/redis/apiv1
JavaIf you are using Maven, add this to your pom.xml file:
<dependency> <groupId>com.google.cloud</groupId> <artifactId>google-cloud-redis</artifactId> <version>0.62.0-alpha</version> </dependency>
If you are using Gradle, add this to your dependencies:
If you are using SBT, add this to your dependencies:
libraryDependencies += "com.google.cloud" % "google-cloud-redis" % "0.62.0-alpha"
If you're using IntelliJ or Eclipse, you can add client libraries to your project using these IDE plugins:
The plugins provide additional functionality, such as key management for service accounts. Refer to each plugin's documentation for details.
npm install --save @google-cloud/redis
composer require google/cloud-redis
PythonFor more on setting up your Python development environment, refer to Python Development Environment Setup Guide.
pip install --upgrade google-cloud-redis
gem install google-cloud-redis
Setting up authentication
To run the client library, you must first set up authentication by creating a service account and setting an environment variable.
In the Cloud Console, go to the Create service account key page.Go to the Create Service Account Key page
- From the Service account list, select New service account.
- In the Service account name field, enter a name.
From the Role list, select Project > Owner.Note: The Role field authorizes your service account to access resources. You can view and change this field later by using the Cloud Console. If you are developing a production app, specify more granular permissions than Project > Owner. For more information, see granting roles to service accounts.
- Click Create. A JSON file that contains your key downloads to your computer.
Create the service account. Replace [NAME] with a name for the service account.
gcloud iam service-accounts create [NAME]
Grant permissions to the service account. Replace [PROJECT_ID] with your project ID.
gcloud projects add-iam-policy-binding [PROJECT_ID] --member "serviceAccount:[NAME]@[PROJECT_ID].iam.gserviceaccount.com" --role "roles/owner"
Generate the key file. Replace [FILE_NAME] with a name for the key file.
gcloud iam service-accounts keys create [FILE_NAME].json --iam-account [NAME]@[PROJECT_ID].iam.gserviceaccount.com
Provide authentication credentials to your application code by setting the environment variable GOOGLE_APPLICATION_CREDENTIALS. Replace [PATH] with the file path of the JSON file that contains your service account key, and [FILE_NAME] with the filename. This variable only applies to your current shell session, so if you open a new session, set the variable again.
Linux or macOS
With command prompt: