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-03-20 20:41:36 +08:00
|
|
|
redis, err := NewDefault(&Config{
|
2023-01-15 00:21:08 +08:00
|
|
|
Addr: "127.0.0.1:6379",
|
|
|
|
Password: "",
|
|
|
|
DB: 15,
|
|
|
|
PoolSize: 16,
|
|
|
|
MinIdleConn: 4,
|
|
|
|
MaxConnAge: "1h",
|
|
|
|
IdleTimeout: "10m",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer redis.Close()
|
|
|
|
|
2023-05-17 19:14:45 +08:00
|
|
|
set, err := redis.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:14:45 +08:00
|
|
|
get, err := redis.Get(context.Background(), "name").Result()
|
2023-01-15 00:21:08 +08:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(get)
|
|
|
|
}
|