Documentation ¶
Overview ¶
Package redistest provides test helpers to manage a redis server.
Index ¶
- Constants
- Variables
- func NewPool(t *testing.T, addr string) *redis.Pool
- func StartCluster(t *testing.T, w io.Writer) (func(), []string)
- func StartClusterWithReplicas(t *testing.T, w io.Writer) (func(), []string)
- func StartServer(t *testing.T, w io.Writer, conf string) (*exec.Cmd, string)
- type MockServer
Constants ¶
const NumClusterNodes = 3
NumClusterNodes is the number of nodes started in a test cluster. When a cluster is started with replicas, there is 1 replica per cluster node, so the total number of nodes is NumClusterNodes * 2.
Variables ¶
var ClusterConfig = `
port %s
cluster-enabled yes
cluster-config-file nodes.%[1]s.conf
cluster-node-timeout 5000
appendonly no
`
ClusterConfig is the configuration to use for servers started in redis-cluster mode. The value must contain a single reference to a string placeholder (%s), the port number.
Functions ¶
func StartCluster ¶
StartCluster starts a redis cluster of NumClusterNodes using the ClusterConfig variable as configuration. If w is not nil, stdout and stderr of each node will be written to it.
It returns a function that should be called after the test (typically in a defer), and the list of ports for all nodes in the cluster.
func StartClusterWithReplicas ¶
StartClusterWithReplicas starts a redis cluster of NumClusterNodes with 1 replica each. It returns the cleanup function to call after use (typically in a defer) and the list of ports for each node, masters first, then replicas.
func StartServer ¶
StartServer starts a redis-server instance on a free port. It returns the started *exec.Cmd and the port used. The caller should make sure to stop the command. If the redis-server command is not found in the PATH, the test is skipped.
If w is not nil, both stdout and stderr of the server are written to it. If a configuration is specified, it is supplied to the server via stdin.
Types ¶
type MockServer ¶
type MockServer struct { Addr string // contains filtered or unexported fields }
MockServer is a mock redis server.
func StartMockServer ¶
func StartMockServer(t *testing.T, handler func(cmd string, args ...string) interface{}) *MockServer
StartMockServer creates and starts a mock redis server. The handler is called for each command received by the server. The returned value is encoded in the redis protocol and sent to the client. The caller should close the server after use.