0

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: enter image description here

Thanks in advance.

chetanspeed511987
  • 1,995
  • 2
  • 22
  • 34

1 Answers1

2

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

David
  • 334
  • 3
  • 3