Documentation ¶
Overview ¶
Package randomredis is a utility for starting and stopping Redis servers on random ports Useful for testing applications that utilize Redis within code to provide predictable i/o
Index ¶
Constants ¶
const ( // StatusStarting is a value for a starting server StatusStarting = 1 // StatusRunning is a value for a running server StatusRunning = 2 // StatusKilled is a value for a killed server StatusKilled = 3 )
Variables ¶
var ( // RedisFileLocation represents the location that all files relating // to a Redis server should be located in // NOTE: Should start with a leading slash but have no trailing slash // NOTE: Public variable to allow package authors the ability // to change this before starting the Redis server RedisFileLocation = "/tmp" // RedisCommand represents the command to be run when starting a Redis server // NOTE: Public variable to allow package authors the ability // to change this before starting the Redis server RedisCommand = "redis-server" // ServerHost is the host to run the Redis server on // NOTE: Public variable to allow package authors the ability // to change this before starting the Redis server ServerHost = "localhost" )
Functions ¶
This section is empty.
Types ¶
type RedisServer ¶
type RedisServer struct {
// contains filtered or unexported fields
}
RedisServer is a struct representing a single Redis server listening on a random port
func NewServer ¶
func NewServer() (*RedisServer, error)
NewServer attempts to create, start, and return a new Redis server operating on a random port
func (*RedisServer) Addr ¶
func (s *RedisServer) Addr() string
Addr returns the address of the Redis server with the pattern of: {host}:{port}
func (*RedisServer) Flush ¶
func (s *RedisServer) Flush() error
Flush is used to flush all key/value pairs from a Redis server by running a `FlushAll` command For more information on the `FlushAll` command, see http://redis.io/commands/flushall
func (*RedisServer) GetStatus ¶
func (s *RedisServer) GetStatus() int
GetStatus returns a server's internal status property NOTE: It is advisable to check the value returned from this method against one of the status contstants defined in this package
func (*RedisServer) Host ¶
func (s *RedisServer) Host() string
Host returns the host of the Redis server
func (*RedisServer) ID ¶
func (s *RedisServer) ID() string
ID returns the unique ID of the Redis server
func (*RedisServer) Ping ¶
func (s *RedisServer) Ping() error
Ping returns the output of running a `Ping` command on the Redis server For more information on the `Ping` command, see http://redis.io/commands/ping
func (*RedisServer) Port ¶
func (s *RedisServer) Port() int
Port returns the port of the Redis server
func (*RedisServer) Stop ¶
func (s *RedisServer) Stop() error
Stop attempts to stop a currently-running Redis server