Documentation ¶
Index ¶
- func AddLockExpects(conn *redigomock.Conn, name interface{}, expects ...interface{}) *redigomock.Cmd
- func ConnDialer(fake redis.Conn) redsync.Dialer
- func NewThreadsafeConn(conn redis.Conn) redis.Conn
- func PoolsForConn(conn redis.Conn, n int) (pools []*redis.Pool)
- type ThreadsafeConn
- func (t ThreadsafeConn) Close() error
- func (t ThreadsafeConn) Do(commandName string, args ...interface{}) (reply interface{}, err error)
- func (t ThreadsafeConn) Err() error
- func (t ThreadsafeConn) Flush() error
- func (t ThreadsafeConn) Receive() (reply interface{}, err error)
- func (t ThreadsafeConn) Send(commandName string, args ...interface{}) error
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 ¶
ConnDialer returns fake as its connection. This is generally useful for fake connections- use TcpDialer or UnixDialer for real connections.
func NewThreadsafeConn ¶
NewThreadsafeConn initializes the mutex.
Types ¶
type ThreadsafeConn ¶
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