The Redis client returns the redis: nil error
I am writing a client wrapper Redis for caching data downloaded from online services:
import (
"github.com/go-redis/redis/v7"
)
type Cache struct {
client *redis.Client
}
// Инициализация из примера в документации
func NewRedisClient() *redis.Client {
return redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password set
DB: 0, // use default DB
})
}
func NewAudioCache() *Cache {
ret := &Cache{client: service.NewRedisClient()}
// ret.client.HSet("test", ExclKey, "C")
// log.Println(ret.client.HGetAll("test").Result())
return ret
}
func (c *Cache) ExclusionsByProcessor(processor common.ProcessorType) ([]string, error) {
res, err := c.client.HGet(ExclKey, processor.String()).Result()
if err != nil {
return nil, err
}
return strings.Split(res, ","), nil
}
On a host with golang 1.12/SparkyLinux, calling wrapper methods works correctly, and on golang 1.13/ArchLinux, it throws an error redis: nil
in ExclusionsByProcessor()
and other methods.
Ping()
works everywhere. The commented out code in NewAudioCache()
also works.
2
Author: George Turin, 2019-10-14
1 answers
The error redis.Nil
means that there is nothing in the database for this key
. Make sure that the key exists, for example via
redis-cli
.
0
Author: Ainar-G, 2019-10-14 09:34:12