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 ¶
ConnDialer returns fake as its connection. This is generally useful for fake connections- use TcpDialer or UnixDialer for real connections.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.