From e679b9ca60edaec1b82106d3def3fc9a4cf3da98 Mon Sep 17 00:00:00 2001 From: Mario L Gutierrez Date: Sat, 27 Jun 2015 07:49:00 -0700 Subject: [PATCH] redis cache: check for nil --- kvs/redis.go | 8 +++++++- sqlx-runner/exec.go | 6 +++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/kvs/redis.go b/kvs/redis.go index 881810a..92bc989 100644 --- a/kvs/redis.go +++ b/kvs/redis.go @@ -72,7 +72,13 @@ func (rs *RedisStore) Get(key string) (string, error) { defer conn.Close() key = rs.ns + key - return redis.String(conn.Do("GET", key)) + s, err := redis.String(conn.Do("GET", key)) + if err == redis.ErrNil { + return "", ErrNotFound + } else if err != nil { + return "", err + } + return s, nil } // Del deletes a key diff --git a/sqlx-runner/exec.go b/sqlx-runner/exec.go index 88fa3a3..54f1194 100644 --- a/sqlx-runner/exec.go +++ b/sqlx-runner/exec.go @@ -422,7 +422,7 @@ func cacheOrSQL(execer *Execer) (sql string, args []interface{}, value []byte, e v, err := Cache.Get(execer.cacheID) //logger.Warn("DBG cacheOrSQL.1 getting by id", "id", execer.cacheID, "v", v, "err", err) if err != nil && err != kvs.ErrNotFound { - logger.Error("Unable to read cache key. Continuing with query", "key", execer.cacheID) + logger.Error("Unable to read cache key. Continuing with query", "key", execer.cacheID, "err", err) } else if v != "" { //logger.Warn("DBG cacheOrSQL.11 HIT", "v", v) return "", nil, []byte(v), nil @@ -472,10 +472,10 @@ func setCache(execer *Execer, data interface{}, dataType int) { case dtStruct: b, err := json.Marshal(data) if err != nil { - logger.Warn("Could not marshal data, clearing", "key", execer.cacheID) + logger.Warn("Could not marshal data, clearing", "key", execer.cacheID, "err", err) err = Cache.Del(execer.cacheID) if err != nil { - logger.Error("Could not delete cache key", "key", execer.cacheID) + logger.Error("Could not delete cache key", "key", execer.cacheID, "err", err) } return }