-
-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redis Get silently returns an empty []byte for stored []byte values #222
Comments
@eko update: |
related #197 |
Redis cache apparently only supports strings not []byte func (c *Cache[T]) Get(ctx context.Context, key any) (T, error) {
cacheKey := c.getCacheKey(key)
value, err := c.codec.Get(ctx, cacheKey)
if err != nil {
return *new(T), err
}
if v, ok := value.(T); ok { // value is always string for redis
return v, nil
}
return *new(T), nil // returns nil, nil or empty, nil for any non string type
} And with interface of codec that doesn't receive and type information in parameters it's not really possible to properly assert anything unless interface is changed to allow this: |
The issue is similar to #166 but for Redis with []byte values. When getting a []byte value the cache returns an empty []byte without an error. This is because the Redis implementation always returns strings and fails when trying to convert the value to string. Since it silently fails, it was difficult to debug.
Steps for Reproduction
Expected behavior:
The returned value is the stored []byte not and empty value
Actual behavior:
It silently returns an empty []byte instead of the stored value
Platforms:
macOS and dockerized Linux from scratch
Versions:
gocache v4.1.3
go 1.21
Redis store v4.2.0
Redis client v9.0.5
Redis server 7.0.12
The text was updated successfully, but these errors were encountered: