redistest

package
v2.10.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package redistest provides a lightweight in-process Redis stub for unit tests.

Use New to start an in-process Redis server. The server is automatically stopped when the test completes.

srv := redistest.New(t)
client, err := redis.NewWithConfig(&redis.Config{
    Addrs: []string{srv.Addr()},
})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is an in-process Redis stub backed by miniredis.Miniredis.

func New

func New(tb testing.TB) *Server

New starts an in-process Redis stub and registers tb.Cleanup to stop it when the test completes.

func (*Server) Addr

func (s *Server) Addr() string

Addr returns the network address (host:port) of the in-process server. Pass this as one of the entries in [redis.Config.Addrs]:

srv := redistest.New(t)
client, _ := redis.NewWithConfig(&redis.Config{Addrs: []string{srv.Addr()}})

func (*Server) Miniredis

func (s *Server) Miniredis() *miniredis.Miniredis

Miniredis returns the underlying *miniredis.Miniredis for fine-grained control in tests: setting key values directly, advancing the fake clock, or simulating connection failures via miniredis.Miniredis.SetError.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL