英文:
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)
}
}
提前感谢。
英文:
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)
}
}
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论