эко-кеш для redis :: магазин.RedisStore не реализует store.Интерфейс магазина

#go #redis #glide-golang #golang-migrate #go-redis

#Вперед #redis #скольжение-golang #golang-миграция #go-redis

Вопрос:

Я использую эту библиотеку 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(amp;redis.Options{
    Addr: "localhost:6379",
}), nil)

fmt.Println("redisStore", redisStore)

cacheManager := cache.New(redisStore)
err := cacheManager.Set("my-key", "my-value", amp;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)
}
 

}

Ошибка ошибки:
введите описание изображения здесь

Заранее спасибо.

Ответ №1:

Попробуйте использовать «github.com/eko/gocache/v2 » (это имя пакета для версии V2). Это решило проблему для меня.