redistest

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2018 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Overview

Package redistest provides test helpers to manage a redis server.

Index

Constants

View Source
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

View Source
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 NewPool

func NewPool(t *testing.T, addr string) *redis.Pool

NewPool creates a redis pool to return connections on the specified addr.

func StartCluster

func StartCluster(t *testing.T, w io.Writer) (func(), []string)

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

func StartClusterWithReplicas(t *testing.T, w io.Writer) (func(), []string)

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

func StartServer(t *testing.T, w io.Writer, conf string) (*exec.Cmd, string)

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.

func (*MockServer) Close

func (s *MockServer) Close()

Close closes the mock redis server.

Directories

Path Synopsis
Package resp implements an efficient decoder for the Redis Serialization Protocol (RESP).
Package resp implements an efficient decoder for the Redis Serialization Protocol (RESP).

Jump to

Keyboard shortcuts

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