2023-03-20 15:50:45 +08:00
|
|
|
package myredis
|
2023-01-15 00:21:08 +08:00
|
|
|
|
|
|
|
import (
|
2023-05-17 19:14:45 +08:00
|
|
|
"context"
|
2023-01-15 00:21:08 +08:00
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRedis(t *testing.T) {
|
2023-05-17 19:56:42 +08:00
|
|
|
err := InitDefault(&Config{
|
|
|
|
Addr: "192.168.244.128:6379",
|
2023-01-15 00:21:08 +08:00
|
|
|
Password: "",
|
|
|
|
DB: 15,
|
|
|
|
PoolSize: 16,
|
|
|
|
MinIdleConn: 4,
|
|
|
|
MaxConnAge: "1h",
|
|
|
|
IdleTimeout: "10m",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
}
|
2023-05-17 19:56:42 +08:00
|
|
|
defer CloseAll()
|
2023-01-15 00:21:08 +08:00
|
|
|
|
2023-05-17 19:56:42 +08:00
|
|
|
set, err := Instance().Set(context.Background(), "name", "qwe123", time.Minute).Result()
|
2023-01-15 00:21:08 +08:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fmt.Println(set)
|
|
|
|
|
2023-05-17 19:56:42 +08:00
|
|
|
get, err := Instance().Get(context.Background(), "name").Result()
|
2023-01-15 00:21:08 +08:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(get)
|
|
|
|
}
|