[英]eko gocache for redis :: store.RedisStore does not implement store.StoreInterface
我正在將這個庫https://github.com/eko/gocache用於 redis 和 go lang
我的代碼是
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)
}
}
提前致謝。
嘗試使用“github.com/eko/gocache/v2”(這是 V2 版本的 package 名稱)。 這為我解決了這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.