mirror of
https://github.com/chai2010/advanced-go-programming-book.git
synced 2025-05-24 04:22:22 +00:00
Update ch6-02-lock.md
如果redis没有"counter"这个key, getResp.Int64()会返回redis.Nil导致"counter"key无法设置
This commit is contained in:
parent
875009fff8
commit
de5f28ec56
@ -176,7 +176,7 @@ func incr() {
|
|||||||
// counter ++
|
// counter ++
|
||||||
getResp := client.Get(counterKey)
|
getResp := client.Get(counterKey)
|
||||||
cntValue, err := getResp.Int64()
|
cntValue, err := getResp.Int64()
|
||||||
if err == nil {
|
if err == nil || err == redis.Nil {
|
||||||
cntValue++
|
cntValue++
|
||||||
resp := client.Set(counterKey, cntValue, 0)
|
resp := client.Set(counterKey, cntValue, 0)
|
||||||
_, err := resp.Result()
|
_, err := resp.Result()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user