使用 redigo 库 (go 中的 Redis 客户端) 进行项目单元测试的简单方法
Easy way to unit test projects using redigo library (Redis client in go). You can find the latest release here.
go get -u github.com/rafaeljusto/redigomock/v3Here is an example of using redigomock, for more information please check the API documentation.
……// Note you cannot get access to the connection via the pool,
// the only way is to use this conn variable.
conn := redigomock.NewConn()
pool := &redis.Pool{
// Return the same connection mock for each Get() call.
Dial: func() (redis.Conn, error) { return conn, nil },
MaxIdle: 10,
}Sometimes you need to check the executed arguments in your Redis command. For that you can use the command handler.
…暂无开放 Issues,或尚未同步最近议题。