设置客户端库

本页介绍了如何为 Memorystore for Redis API 安装客户端库,以便您可以使用自己选择的语言连接到 API。

安装客户端库

C++

如需详细了解此客户端库的要求和安装依赖项,请参阅设置 C++ 开发环境

C#

在 Visual Studio 中安装 Google.Cloud.Redis.V1 软件包

Go

go get cloud.google.com/go/redis/apiv1

Java

如果您使用的是 Maven,请将以下内容添加到您的 pom.xml 文件中:

<dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>google-cloud-redis</artifactId>
    <version>0.62.0-alpha</version>
</dependency>

如果您使用的是 Gradle,请将以下内容添加到您的依赖项中:

compile 'com.google.cloud:google-cloud-redis:0.62.0-alpha'

如果您使用的是 SBT,请将以下内容添加到您的依赖项中:

libraryDependencies += "com.google.cloud" % "google-cloud-redis" % "0.62.0-alpha"

如果您使用的是 VS Code、IntelliJ 或 Eclipse,则可使用以下 IDE 插件将客户端库添加到您的项目中:

上述插件还提供其他功能,例如服务账号密钥管理。详情请参阅各个插件相应的文档。

Node.js

npm install @google-cloud/redis

PHP

composer require google/cloud-redis

Python

如需详细了解如何设置 Python 开发环境,请参阅 Python 开发环境设置指南
pip install --upgrade google-cloud-redis

Ruby

gem install google-cloud-redis

设置身份验证

  1. After installing the Google Cloud CLI, initialize it by running the following command:

    gcloud init

    If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  2. If you're using a local shell, then create local authentication credentials for your user account:

    gcloud auth application-default login

    You don't need to do this if you're using Cloud Shell.

    If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

    登录屏幕随即出现。在您登录后,您的凭据会存储在 ADC 使用的本地凭据文件中。

其他资源