redistest

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2019 License: MIT Imports: 12 Imported by: 1

README

go-test-redisserver

wercker status GoDoc

redis-server runner for tests. go-test-redisserver is a port of Test::RedisServer.

USAGE

package main

import (
        "github.com/soh335/go-test-redisserver"
        "github.com/garyburd/redigo/redis"
)

func main() {
        s, err := redistest.NewServer(true, nil)
        if err != nil {
                panic(err)
        }
        defer s.Stop()
        conn, err := redis.Dial("unix", s.Config["unixsocket"])
        if err != nil {
                panic(err)
        }
        _, err = conn.Do("PING")
        if err != nil {
                panic(err)
        }
}

LICENSE

  • MIT

SEE ALSO

Documentation

Overview

Package redistest privides temporary redis-server for testing.

This is basic usage of redistest.

s, err := redistest.NewServer(true, nil)
if err != nil {
	panic(err)
}
defer s.Stop()
conn, err := redis.Dial("unix", s.Config["unixsocket"])
if err != nil {
	panic(err)
}
_, err = conn.Do("PING")
if err != nil {
	panic(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config map[string]string

Config is configuration of redis-server.

type Error

type Error struct {
	Err error
	Log string
}

Error is error while starting redis

func (*Error) Cause

func (err *Error) Cause() error

Cause returns the underlying cause of the error. The error can be inspected by errors.Cause https://github.com/pkg/errors

func (*Error) Error

func (err *Error) Error() string

type Server

type Server struct {
	Config Config

	TempDir string
	TimeOut time.Duration
	// contains filtered or unexported fields
}

Server is main struct of redistest.

func NewServer

func NewServer(autostart bool, config Config) (*Server, error)

NewServer create a new Server. If config is nil, redistest use default value. It means use unixsocket, dir is random.

func (*Server) Start

func (server *Server) Start() error

Start start redis-server.

func (*Server) Stop

func (server *Server) Stop() error

Stop stop redis-server

Jump to

Keyboard shortcuts

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