Documentation
¶
Overview ¶
Package redis includes Redis implementation of Gnomock Preset interface. This Preset can be passed to gnomock.StartPreset function to create a configured Redis container to use in tests
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*options)
Option is an optional configuration of this Gnomock preset. Use available Options to configure the container
func WithValues ¶
WithValues initializes Redis with the provided key/value pairs. These values never expire. See go-redis/redis package for information on supported value types
type Redis ¶
type Redis struct {
// contains filtered or unexported fields
}
Redis is a Gnomock Preset implementation for redis storage
Example ¶
vs := make(map[string]interface{}) vs["a"] = "foo" vs["b"] = 42 vs["c"] = true p := mockredis.Preset(mockredis.WithValues(vs)) container, _ := gnomock.StartPreset(p) defer func() { _ = gnomock.Stop(container) }() client := redis.NewClient(&redis.Options{Addr: container.Address()}) fmt.Println(client.Get("a").Result()) var number int err := client.Get("b").Scan(&number) fmt.Println(number, err) var flag bool err = client.Get("c").Scan(&flag) fmt.Println(flag, err)
Output: foo <nil> 42 <nil> true <nil>
func Preset ¶
Preset creates a new Gmomock Redis preset. This preset includes a Redis specific healthcheck function, default Redis image and port, and allows to optionally set up initial state