Closed hom-bahrani closed 5 years ago
Sure, let me explain.
*redismock.ClientMock
is struct
. Structs can have instance variables and methods (basically the same thing as a class
in most other languages). redis.Cmdable
is an interface
. Interfaces work the same way as interfaces in other languages (they define a set of methods that must be implemented).
In Go any struct will implement an interface by simply having the all the method signatures in that interface. Unlike other languages that require the class to explicitly say implements redis.Cmdable
.
redis.Cmdable
is a massive interface, and it grows with each release of the redis
package. However, as long as ClientMock
has at least all of the methods defined in the interface it can always be used as such.
Does that answer your question?
thanks @elliotchance thats perfect 👍
Firstly thanks for writing this package, and please forgive my ignorance I'm new to Go. In your example
newTestRedis()
returns a type of*redismock.ClientMock
which is saved in the variabler
. How can this be passed into theRedisIsAvailable
function which is expecting a type ofredis.Cmdable
.