github.com/shuguocloud/go-zero@v1.3.0/core/stores/redis/redistest/redistest.go (about) 1 package redistest 2 3 import ( 4 "time" 5 6 "github.com/alicebob/miniredis/v2" 7 "github.com/shuguocloud/go-zero/core/lang" 8 "github.com/shuguocloud/go-zero/core/stores/redis" 9 ) 10 11 // CreateRedis returns a in process redis.Redis. 12 func CreateRedis() (r *redis.Redis, clean func(), err error) { 13 mr, err := miniredis.Run() 14 if err != nil { 15 return nil, nil, err 16 } 17 18 return redis.New(mr.Addr()), func() { 19 ch := make(chan lang.PlaceholderType) 20 go func() { 21 mr.Close() 22 close(ch) 23 }() 24 select { 25 case <-ch: 26 case <-time.After(time.Second): 27 } 28 }, nil 29 }