You need to enable JavaScript to run this app.
文档中心
缓存数据库 Redis 版

缓存数据库 Redis 版

复制全文
下载 pdf
Go SDK
初始化客户端
复制全文
下载 pdf
初始化客户端
Redis Go SDK 支持通过 Session 的方式来初始化客户端。通过 Session 方式创建的 Redis 客户端,底层会实现 HTTP/HTTPS 资源(连接或请求)的复用。当需要初始化多个客户端进行操作时,通过 Session 方式创建可以提升客户端的性能。本文介绍如何通过 Session 的方式来初始化客户端。​
前提条件​
  • 已下载并安装 Redis Go SDK。具体操作步骤,请参见下载安装 SDK。​
  • 初始化客户端之前,需确保已获取如下信息:​
  • 账号的 Access Key ID(简称 AK)和 Secret Access Key(简称 SK)信息。获取 AKSK 信息的方法,请参见 Access Key 管理。​
  • Region 信息。Redis 支持的 Region,请参见服务地址。​
初始化客户端​
使用如下代码初始化客户端。​
​
package main​
​
import (​
"fmt"​
"os"​
​
"github.com/volcengine/volcengine-go-sdk/service/redis"​
"github.com/volcengine/volcengine-go-sdk/volcengine"​
"github.com/volcengine/volcengine-go-sdk/volcengine/credentials"​
"github.com/volcengine/volcengine-go-sdk/volcengine/session"​
)​
​
func main() {​
var (​
ak string​
sk string​
region string​
config *volcengine.Config​
sess *session.Session​
client *redis.REDIS​
err error​
)​
​
// Set access key and secret key verification information and region.​
ak = "Your AK"​
sk = "Your SK"​
region = "Your Region"​
config = volcengine.NewConfig().WithCredentials(credentials.NewStaticCredentials(ak, sk, "")).​
WithRegion(region)​
​
// All clients require sessions, which provide settings shared by them, such as access key and secret key verification information and region information.​
sess, err = session.NewSession(config)​
if err != nil {​
fmt.Printf("Failed to create session, err: %v\n", err)​
os.Exit(1)​
}​
​
// Create a Redis SDK client, which can be used to call the API to perform task requests later.​
client = redis.New(sess)​
}​
​
​
最近更新时间:2026.02.27 16:25:20
这个页面对您有帮助吗?
有用
有用
无用
无用