1
0
mirror of https://github.com/chai2010/advanced-go-programming-book.git synced 2025-05-23 20:02:22 +00:00

Update ch6-02-lock.md

如果redis没有"counter"这个key,  getResp.Int64()会返回redis.Nil导致"counter"key无法设置
This commit is contained in:
Himer 2019-04-23 20:27:55 +08:00 committed by GitHub
parent 875009fff8
commit de5f28ec56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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