eko gocache for redis :: store.RedisStore没有实现store.StoreInterface接口

huangapple go评论68阅读模式
英文:

eko gocache for redis :: store.RedisStore does not implement store.StoreInterface

问题

我正在使用这个库https://github.com/eko/gocache来在Go语言中使用Redis。

我的代码如下:

package main

import (
	"context"
	"fmt"
	"time"

	"github.com/eko/gocache/cache"
	"github.com/eko/gocache/store"
	"github.com/go-redis/redis/v8"
)

func main() {
	ctx := context.Background()

	redisStore := store.NewRedis(redis.NewClient(&redis.Options{
		Addr: "localhost:6379",
	}), nil)

	fmt.Println("redisStore", redisStore)

	cacheManager := cache.New(redisStore)
	err := cacheManager.Set("my-key", "my-value", &store.Options{Expiration: 15 * time.Second})
	if err != nil {
		panic(err)
	}

	value, err := cacheManager.Get(ctx, "my-key")
	switch err {
	case nil:
		fmt.Printf("从Redis缓存中获取键 '%s'。结果:%s", "my-key", value)
	case redis.Nil:
		fmt.Printf("无法在Redis缓存中找到键 '%s'。", "my-key")
	default:
		fmt.Printf("无法通过键 '%s' 从Redis缓存中获取值:%v", "my-key", err)
	}
}

错误的截图:
eko gocache for redis :: store.RedisStore没有实现store.StoreInterface接口

提前感谢。

英文:

I am using this library https://github.com/eko/gocache for redis with go lang

My code is

package main

import (
"context"
"fmt"
"time"

"github.com/eko/gocache/cache"
"github.com/eko/gocache/store"
"github.com/go-redis/redis/v8"

)

func main() {

ctx := context.Background()`

redisStore := store.NewRedis(redis.NewClient(&redis.Options{
	Addr: "localhost:6379",
}), nil)

fmt.Println("redisStore", redisStore)

cacheManager := cache.New(redisStore)
err := cacheManager.Set("my-key", "my-value", &store.Options{Expiration: 15 * time.Second})
if err != nil {
	panic(err)
}

value, err := cacheManager.Get(ctx, "my-key")
switch err {
case nil:
	fmt.Printf("Get the key '%s' from the redis cache. Result: %s", "my-key", value)
case redis.Nil:
	fmt.Printf("Failed to find the key '%s' from the redis cache.", "my-key")
default:
	fmt.Printf("Failed to get the value from the redis cache with key '%s': %v", "my-key", err)
}

}

Scrrenshot of error:
eko gocache for redis :: store.RedisStore没有实现store.StoreInterface接口

Thanks in advance.

答案1

得分: 2

尝试使用"github.com/eko/gocache/v2"(这是V2版本的包名)。这对我解决了问题。

英文:

Try using "github.com/eko/gocache/v2" (which is the package name for the V2 release). This solved the issue for me.

huangapple
  • 本文由 发表于 2021年12月6日 20:13:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/70245336.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定