I tried to download go-redis using this command go get github.com/go-redis/redis/v8
but I got this following error :
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
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 run main.go
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.