Files
rustdesk-api/lib/cache/cache_test.go
T
thomasandClaude Opus 4.8 16e97c8efa i18n: Translate all Chinese to English across the codebase
Translate Chinese comments, log/error messages, validator labels and
Swagger annotations to English throughout the source code, generated
Swagger docs, config files and CI workflows.

Make the English README primary: README.md now holds the English docs
and README_EN.md holds the Chinese version, with cross-language links
updated accordingly.

Note: the generated docs/ swagger files were translated in place; run
`go generate ./...` (swag init) to regenerate them from the now-English
annotations when a Go toolchain is available.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-27 12:17:04 +02:00

93 lines
1.5 KiB
Go

package cache
import (
"fmt"
"github.com/go-redis/redis/v8"
"reflect"
"testing"
)
func TestSimpleCache(t *testing.T) {
type st struct {
A string
B string
}
items := map[string]interface{}{}
items["a"] = "b"
items["b"] = "c"
ab := &st{
A: "a",
B: "b",
}
items["ab"] = *ab
a := items["a"]
fmt.Println(a)
b := items["b"]
fmt.Println(b)
ab.A = "aa"
ab2 := st{}
ab2 = (items["ab"]).(st)
fmt.Println(ab2, reflect.TypeOf(ab2))
}
func TestFileCacheSet(t *testing.T) {
fc := New("file")
err := fc.Set("123", "ddd", 0)
if err != nil {
fmt.Println(err.Error())
t.Fatalf("write failed")
}
}
func TestFileCacheGet(t *testing.T) {
fc := New("file")
err := fc.Set("123", "45156", 300)
if err != nil {
t.Fatalf("write failed")
}
res := ""
err = fc.Get("123", &res)
if err != nil {
t.Fatalf("read failed")
}
fmt.Println("res", res)
}
func TestRedisCacheSet(t *testing.T) {
rc := NewRedis(&redis.Options{
Addr: "192.168.1.168:6379",
Password: "", // no password set
DB: 0, // use default DB
})
err := rc.Set("123", "ddd", 0)
if err != nil {
fmt.Println(err.Error())
t.Fatalf("write failed")
}
}
func TestRedisCacheGet(t *testing.T) {
rc := NewRedis(&redis.Options{
Addr: "192.168.1.168:6379",
Password: "", // no password set
DB: 0, // use default DB
})
err := rc.Set("123", "451156", 300)
if err != nil {
t.Fatalf("write failed")
}
res := ""
err = rc.Get("123", &res)
if err != nil {
t.Fatalf("read failed")
}
fmt.Println("res", res)
}