redistest.go 498 B

1234567891011121314151617181920
  1. package redistest
  2. import (
  3. "testing"
  4. "github.com/alicebob/miniredis/v2"
  5. "github.com/wuntsong-org/go-zero-plus/core/stores/redis"
  6. )
  7. // CreateRedis returns an in process redis.Redis.
  8. func CreateRedis(t *testing.T) *redis.Redis {
  9. r, _ := CreateRedisWithClean(t)
  10. return r
  11. }
  12. // CreateRedisWithClean returns an in process redis.Redis and a clean function.
  13. func CreateRedisWithClean(t *testing.T) (r *redis.Redis, clean func()) {
  14. mr := miniredis.RunT(t)
  15. return redis.New(mr.Addr()), mr.Close
  16. }