Files
rustdesk-api/lib/cache/redis_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

95 lines
1.8 KiB
Go

package cache
import (
"fmt"
"github.com/go-redis/redis/v8"
"reflect"
"testing"
)
func TestRedisSet(t *testing.T) {
//rc := New("redis")
rc := RedisCacheInit(&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 TestRedisGet(t *testing.T) {
rc := RedisCacheInit(&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)
}
func TestRedisGetJson(t *testing.T) {
rc := RedisCacheInit(&redis.Options{
Addr: "192.168.1.168:6379",
Password: "", // no password set
DB: 0, // use default DB
})
type r struct {
Aa string `json:"a"`
B string `json:"c"`
}
old := &r{
Aa: "ab", B: "cdc",
}
err := rc.Set("1233", old, 300)
if err != nil {
t.Fatalf("write failed")
}
res := &r{}
err2 := rc.Get("1233", res)
if err2 != nil {
t.Fatalf("read failed")
}
if !reflect.DeepEqual(res, old) {
t.Fatalf("read error")
}
fmt.Println(res, res.Aa)
}
func BenchmarkRSet(b *testing.B) {
rc := RedisCacheInit(&redis.Options{
Addr: "192.168.1.168:6379",
Password: "", // no password set
DB: 0, // use default DB
})
b.ResetTimer()
for i := 0; i < b.N; i++ {
rc.Set("123", "{dsv}", 1000)
}
}
func BenchmarkRGet(b *testing.B) {
rc := RedisCacheInit(&redis.Options{
Addr: "192.168.1.168:6379",
Password: "", // no password set
DB: 0, // use default DB
})
b.ResetTimer()
v := ""
for i := 0; i < b.N; i++ {
rc.Get("123", &v)
}
}