2020-11-02 17:51:33 +08:00
|
|
|
package redistest
|
|
|
|
|
|
|
|
|
|
import (
|
2023-04-01 13:02:21 +08:00
|
|
|
"testing"
|
2020-11-02 17:51:33 +08:00
|
|
|
|
2020-11-16 19:45:43 +08:00
|
|
|
"github.com/alicebob/miniredis/v2"
|
2022-01-04 15:51:32 +08:00
|
|
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
2020-11-02 17:51:33 +08:00
|
|
|
)
|
|
|
|
|
|
2022-11-04 21:55:17 +08:00
|
|
|
// CreateRedis returns an in process redis.Redis.
|
2023-04-01 13:02:21 +08:00
|
|
|
func CreateRedis(t *testing.T) *redis.Redis {
|
|
|
|
|
r, _ := CreateRedisWithClean(t)
|
|
|
|
|
return r
|
|
|
|
|
}
|
2022-02-09 11:06:06 +08:00
|
|
|
|
2023-04-01 13:02:21 +08:00
|
|
|
// CreateRedisWithClean returns an in process redis.Redis and a clean function.
|
|
|
|
|
func CreateRedisWithClean(t *testing.T) (r *redis.Redis, clean func()) {
|
|
|
|
|
mr := miniredis.RunT(t)
|
|
|
|
|
return redis.New(mr.Addr()), mr.Close
|
2020-11-02 17:51:33 +08:00
|
|
|
}
|