You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
704 B
33 lines
704 B
10 months ago
|
package main
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
"github.com/go-redis/redis/v9"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
// redis 客户端
|
||
|
// 此时不会建立连接
|
||
|
//client := redis.NewClient(&redis.Options{
|
||
|
// Addr: "192.168.157.135:3679",
|
||
|
// Username: "default", // ACL 的默认用户名
|
||
|
// Password: "yourPassword",
|
||
|
// DB: 0,
|
||
|
// DialTimeout: 1 * time.Second,
|
||
|
//})
|
||
|
|
||
|
// URL 方式配置选项
|
||
|
opt, err := redis.ParseURL("redis://default:yourPassword@192.168.157.135:6379/0?dial_timeout=1")
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
|
||
|
client := redis.NewClient(opt)
|
||
|
fmt.Println(client)
|
||
|
|
||
|
// 执行操作时,需要获取连接
|
||
|
status := client.Ping(context.Background())
|
||
|
fmt.Println(status.Result())
|
||
|
}
|