feat: 添加 database - cache(redis)

This commit is contained in:
zhaoyupeng
2025-06-18 18:44:45 +08:00
parent 7dd48c0c50
commit edce9fe73f
8 changed files with 475 additions and 9 deletions

39
database/cache/new_test.go vendored Normal file
View File

@ -0,0 +1,39 @@
package cache
import (
"testing"
)
func TestNew(t *testing.T) {
/* if err := Init(WithRedis("127.0.0.1", 6379, "", "MyPassw0rd")); err != nil {
t.Fatal(err)
}
type User struct {
Name string `json:"name"`
Age int `json:"age"`
}
if err := Default.Set(t.Context(), "zyp:haha", &User{
Name: "cache",
Age: 18,
}); err != nil {
t.Fatal(err)
}
s := Default.GetDelScan(t.Context(), "zyp:haha")
u := new(User)
if err := s.Scan(u); err != nil {
t.Fatal(err)
}
t.Logf("%#v", *u)
if err := Default.SetEx(t.Context(), "zyp:haha", &User{
Name: "redis",
Age: 2,
}, time.Hour); err != nil {
t.Fatal(err)
}*/
}