From de5f28ec56eca92dc96b835393008f0172d81bfb Mon Sep 17 00:00:00 2001 From: Himer Date: Tue, 23 Apr 2019 20:27:55 +0800 Subject: [PATCH] Update ch6-02-lock.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 如果redis没有"counter"这个key, getResp.Int64()会返回redis.Nil导致"counter"key无法设置 --- ch6-cloud/ch6-02-lock.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ch6-cloud/ch6-02-lock.md b/ch6-cloud/ch6-02-lock.md index daeb425..9d9fad2 100644 --- a/ch6-cloud/ch6-02-lock.md +++ b/ch6-cloud/ch6-02-lock.md @@ -176,7 +176,7 @@ func incr() { // counter ++ getResp := client.Get(counterKey) cntValue, err := getResp.Int64() - if err == nil { + if err == nil || err == redis.Nil { cntValue++ resp := client.Set(counterKey, cntValue, 0) _, err := resp.Result()