cache
cache copied to clipboard
unknown compression method: 3d
Hello, I'm trying to get a key using this code:
import (
"context"
"time"
"github.com/go-redis/cache/v8"
"github.com/go-redis/redis/v8"
)
timeout := 15 * time.Second
ring := redis.NewRing(&redis.RingOptions{
Addrs: map[string]string{
"shard1": ":6379",
},
DialTimeout: timeout,
ReadTimeout: timeout,
WriteTimeout: timeout,
})
c := cache.New(&cache.Options{
Redis: ring,
})
var wanted interface{}
err := c.GetSkippingLocalCache(context.TODO(), "key", &wanted)
if err != nil {
panic(err)
}
And I got this error: unknown compression method: 3d
Does anyone know how to fix this?
Environment:
- OS: Windows 10 Pro, Ubuntu 20 LTS
- Go 1.17
- go-redis/cache v8
I got this error: unknown compression method: 39
Here is the code:
var value string
err := Get(ctx, "key", value)
func Get(ctx context.Context, key string, dest interface{}){
dest interface{}
err = cache.Cache.Get(ctx, key, &dest)
}
It seems the compression method cannot be recognized.
https://github.com/go-redis/cache/blob/8756f3baa759d22acfdc1dc67f9fbcc0e21e6332/cache.go#L399
@spbjss yes it does. But it shouldn't happen though.
@vincentluan you should be passing variable of specific type when trying to load value from cache and not generic interface. Un-marshal doesn't know how to un-marshal when you give it a generic interface.
try this if cacheValue is string
import (
"context"
"time"
"github.com/go-redis/cache/v8"
"github.com/go-redis/redis/v8"
)
timeout := 15 * time.Second
ring := redis.NewRing(&redis.RingOptions{
Addrs: map[string]string{
"shard1": ":6379",
},
DialTimeout: timeout,
ReadTimeout: timeout,
WriteTimeout: timeout,
})
c := cache.New(&cache.Options{
Redis: ring,
})
var wanted string **// or whatever object you are expecting value to un-marshal into or provide custom un-marhsaller for your object**
err := c.GetSkippingLocalCache(context.TODO(), "key", &wanted)
if err != nil {
panic(err)
}
I came up to same conclusion as @XeQtr792, but It's not very neat.. This is not what I expected using this library.
@XeQtr792 It doesn't seem to be the case because it's working correctly in my other projects. Anyway it seems the issue is fixed with the following versions. Thank you guys for your comments.
github.com/go-redis/cache/v8 v8.4.3
github.com/go-redis/redis/v8 v8.11.4