github.com/isyscore/isc-gobase@v1.5.3-0.20231218061332-cbc7451899e9/extend/redis/test/redis_test.go (about) 1 package test 2 3 import ( 4 "context" 5 goredis "github.com/go-redis/redis/v8" 6 redis2 "github.com/isyscore/isc-gobase/extend/redis" 7 "github.com/magiconair/properties/assert" 8 "testing" 9 "time" 10 ) 11 12 var rdb goredis.UniversalClient 13 14 func init() { 15 // 客户端获取 16 _rdb, err := redis2.NewClient() 17 if err != nil { 18 return 19 } 20 rdb = _rdb 21 } 22 23 func TestRedis(t *testing.T) { 24 // 添加和读取 25 key := "test_key" 26 value := "test_value" 27 28 ctx := context.Background() 29 rdb.Set(ctx, key, value, time.Hour) 30 rlt := rdb.Get(ctx, key) 31 32 // 判断 33 actValue, _ := rlt.Result() 34 assert.Equal(t, actValue, value) 35 }