[英]Error cannot find package "github.com/go-redis/redis/v8" when downloading go-redis package
I tried to download go-redis using this command go get github.com/go-redis/redis/v8
but I got this following error :我尝试使用此命令下载 go-redis go get github.com/go-redis/redis/v8
但出现以下错误:
cannot find package "github.com/go-redis/redis/v8" in any of:
C:\Go\src\github.com\go-redis\redis\v8 (from $GOROOT)
E:\Go Workspace\src\github.com\go-redis\redis\v8 (from $GOPATH)
Why did I get this error and how to fix this ?为什么我会收到此错误以及如何解决此问题?
OS : Windows
Go version : go version go1.15 windows/amd64
Following steps solved my problem:以下步骤解决了我的问题:
go mod init github.com/my/repo
go get github.com/go-redis/redis/v8
Create a main.go file and write the following code to check for your connection创建一个 main.go 文件并编写以下代码来检查您的连接
package main
import (
"fmt"
"github.com/go-redis/redis"
)
func main() {
fmt.Println("Go Redis Connection Test")
client := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "",
DB: 0,
})
pong, err := client.Ping().Result()
fmt.Println(pong, err)
}
When we will run this now, we will see that the Go application will successfully ping the redis instance and it will return a successful PONG response:当我们现在运行它时,我们将看到 Go 应用程序将成功 ping redis 实例并返回一个成功的 PONG 响应:
go run main.go
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.