cache icon indicating copy to clipboard operation
cache copied to clipboard

unknown compression method: 3d

Open vincentluan opened this issue 2 years ago • 5 comments

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

vincentluan avatar Mar 04 '22 03:03 vincentluan

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)
}

spbjss avatar Mar 13 '22 02:03 spbjss

It seems the compression method cannot be recognized.

https://github.com/go-redis/cache/blob/8756f3baa759d22acfdc1dc67f9fbcc0e21e6332/cache.go#L399

spbjss avatar Mar 13 '22 02:03 spbjss

@spbjss yes it does. But it shouldn't happen though.

vincentluan avatar Mar 14 '22 04:03 vincentluan

@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)
}

XeQtr792 avatar Apr 22 '22 01:04 XeQtr792

I came up to same conclusion as @XeQtr792, but It's not very neat.. This is not what I expected using this library.

akhromium avatar Apr 26 '22 18:04 akhromium

@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

vincentluan avatar Nov 09 '22 03:11 vincentluan