rstest

package
v2.0.2+incompatible Latest Latest
Warning

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

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

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddLockExpects

func AddLockExpects(conn *redigomock.Conn, name interface{}, expects ...interface{}) *redigomock.Cmd

AddLockExpects is a helper for adding redigomock.Conn expectations for locking. name is the string name of the mutex or a redigomock.FuzzyMatcher, and expects are each arguments passed to redigomock.Cmd#Expect. For example, if you wanted to acquire the "my-mutex" four times, and succeed the first two times, then fail due to contention, you could use AddLockExpects(mockConn, "my-mutex", "OK", "OK", nil).

Example
package main

import (
	"errors"
	"fmt"
	"github.com/rafaeljusto/redigomock"
	"github.com/rgalanakis/redsync"
	"github.com/rgalanakis/redsync/rstest"
)

func main() {
	conn := redigomock.NewConn()
	rstest.AddLockExpects(conn, "example-lock-expects", "OK", "OK", nil, "e").
		ExpectError(errors.New("uh-oh"))

	pools := rstest.PoolsForConn(conn, 1)
	mutex := redsync.New(pools...).NewMutex("example-lock-expects", redsync.NonBlocking())

	fmt.Println(mutex.Lock())
	fmt.Println(mutex.Lock())
	fmt.Println(mutex.Lock())
	fmt.Println(mutex.Lock())
	fmt.Println(mutex.Lock())
}
Output:

<nil>
<nil>
redsync: failed to acquire lock
redsync: failed to acquire lock
uh-oh

func ConnDialer

func ConnDialer(fake redis.Conn) redsync.Dialer

ConnDialer returns fake as its connection. This is generally useful for fake connections- use TcpDialer or UnixDialer for real connections.

func NewThreadsafeConn

func NewThreadsafeConn(conn redis.Conn) redis.Conn

NewThreadsafeConn initializes the mutex.

func PoolsForConn

func PoolsForConn(conn redis.Conn, n int) (pools []*redis.Pool)

PoolsForConn returns a slice of n redis.Pool instances, all of which return the same connection. See package specs for usage.

Types

type ThreadsafeConn

type ThreadsafeConn struct {
	Conn redis.Conn
	// contains filtered or unexported fields
}

ThreadsafeConn can be used to wrap a redis.Conn that is not threadsafe. This is usually a redigomock.Conn.

func (ThreadsafeConn) Close

func (t ThreadsafeConn) Close() error

func (ThreadsafeConn) Do

func (t ThreadsafeConn) Do(commandName string, args ...interface{}) (reply interface{}, err error)

func (ThreadsafeConn) Err

func (t ThreadsafeConn) Err() error

func (ThreadsafeConn) Flush

func (t ThreadsafeConn) Flush() error

func (ThreadsafeConn) Receive

func (t ThreadsafeConn) Receive() (reply interface{}, err error)

func (ThreadsafeConn) Send

func (t ThreadsafeConn) Send(commandName string, args ...interface{}) error

Jump to

Keyboard shortcuts

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