Open nikjoshistori opened 2 years ago
Hello team I getting below error cannot use redismock.NewClientMock() (value of type *redis.Client) as redis.Cmdable value in assignment
cannot use redismock.NewClientMock() (value of type *redis.Client) as redis.Cmdable value in assignment
For the code below redis.go `package redis
import ( "fmt" "time"
"github.com/go-redis/redis"
)
type redisConn struct { host string port string password string client *redis.Client }
const ( redisPwd = "" redisPort = "6379" )
// RedisNewConn func (r redisConn) RedisNewConn() error {
r.client = redis.NewClient(&redis.Options{ Addr: r.host + ":" + r.port, Password: r.password, }) if r.client == nil { return fmt.Errorf("redis Connection failed") } if _, err := r.client.Ping().Result(); err != nil { return err } return nil
}
// Set func (r redisConn) Set(k string, d string, expiry time.Duration) error {
err := r.client.Set(k, d, expiry).Err() if err != nil { return err } return nil
// Get func (r redisConn) Get(k string) (string, error) {
d, e := r.client.Get(k).Result() if e != nil { return "", e } return d, nil
} redis_test.go package redis
redis_test.go
import ( "testing"
"[github.com/go-redis/redis](http://github.com/go-redis/redis)" "[github.com/go-redis/redismock/v8](http://github.com/go-redis/redismock/v8)"
type mockRedis struct { key string val string client *redis.Client }
func TestGet(t *testing.T) {
var conn redisConn var mock redismock.ClientMock conn.client, mock = redismock.NewClientMock() mockr := mockRedis{key: "news_redis_cache_123456", val: "s"} mock.ExpectGet(mockr.key).SetVal(mockr.val)
}`
Hello team I getting below error
cannot use redismock.NewClientMock() (value of type *redis.Client) as redis.Cmdable value in assignment
For the code below redis.go `package redis
import ( "fmt" "time"
)
type redisConn struct { host string port string password string client *redis.Client }
const ( redisPwd = "" redisPort = "6379" )
// RedisNewConn func (r redisConn) RedisNewConn() error {
}
// Set func (r redisConn) Set(k string, d string, expiry time.Duration) error {
}
// Get func (r redisConn) Get(k string) (string, error) {
}
redis_test.go
package redisimport ( "testing"
)
type mockRedis struct { key string val string client *redis.Client }
func TestGet(t *testing.T) {
}`