enterprise/base/wechat/cache/redis_test.go

33 lines
566 B
Go
Raw Normal View History

2023-08-13 21:24:54 +08:00
package cache
import (
"testing"
"time"
)
func TestRedis(t *testing.T) {
opts := &RedisOpts{
Host: "127.0.0.1:6379",
}
redis := NewRedis(opts)
var err error
timeoutDuration := 1 * time.Second
if err = redis.Set("username", "silenceper", timeoutDuration); err != nil {
t.Error("set Error", err)
}
if !redis.IsExist("username") {
t.Error("IsExist Error")
}
name := redis.Get("username").(string)
if name != "silenceper" {
t.Error("get Error")
}
if err = redis.Delete("username"); err != nil {
t.Errorf("delete Error , err=%v", err)
}
}