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
|
|
|
|
}
|
2024-06-01 18:28:09 +08:00
|
|
|
defer CloseAllDB()
|
2023-01-15 00:21:08 +08:00
|
|
|
|
2024-06-01 18:17:41 +08:00
|
|
|
set, err := DB().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)
|
|
|
|
|
2024-06-01 18:17:41 +08:00
|
|
|
get, err := DB().Get(context.Background(), "name").Result()
|
2023-01-15 00:21:08 +08:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(get)
|
|
|
|
}
|