github.com/gogf/gf@v1.16.9/database/gredis/gredis_z_unit_conn_test.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 package gredis_test 8 9 import ( 10 "github.com/gogf/gf/database/gredis" 11 "github.com/gogf/gf/test/gtest" 12 "testing" 13 "time" 14 ) 15 16 func TestConn_DoWithTimeout(t *testing.T) { 17 gtest.C(t, func(t *gtest.T) { 18 redis := gredis.New(config) 19 t.AssertNE(redis, nil) 20 conn := redis.Conn() 21 defer conn.Close() 22 23 _, err := conn.DoWithTimeout(time.Second, "set", "test", "123") 24 t.Assert(err, nil) 25 defer conn.DoWithTimeout(time.Second, "del", "test") 26 27 r, err := conn.DoWithTimeout(time.Second, "get", "test") 28 t.Assert(err, nil) 29 t.Assert(r, "123") 30 }) 31 } 32 33 func TestConn_ReceiveVarWithTimeout(t *testing.T) { 34 gtest.C(t, func(t *gtest.T) { 35 redis := gredis.New(config) 36 t.AssertNE(redis, nil) 37 conn := redis.Conn() 38 defer conn.Close() 39 40 _, err := conn.DoVarWithTimeout(time.Second, "Subscribe", "gf") 41 t.Assert(err, nil) 42 43 v, err := redis.DoVarWithTimeout(time.Second, "PUBLISH", "gf", "test") 44 t.Assert(err, nil) 45 t.Assert(v.String(), "1") 46 47 v, _ = conn.ReceiveVar() 48 t.Assert(len(v.Strings()), 3) 49 t.Assert(v.Strings()[2], "test") 50 }) 51 }