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:
parent
875009fff8
commit
de5f28ec56
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user