Skip to content

Commit

Permalink
Handle redis nil error
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Mar 29, 2020
1 parent cd713bd commit 0870ae0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion stores/redisstore/go.mod
Expand Up @@ -2,4 +2,7 @@ module github.com/clevergo/captchas/stores/redisstore

go 1.14

require github.com/go-redis/redis/v7 v7.2.0
require (
github.com/clevergo/captchas v0.3.2
github.com/go-redis/redis/v7 v7.2.0
)
2 changes: 2 additions & 0 deletions stores/redisstore/go.sum
@@ -1,3 +1,5 @@
github.com/clevergo/captchas v0.3.2 h1:/P/Lc8umYp052aGeyiQf8a8mED+g+lmZLqmogMrt1e0=
github.com/clevergo/captchas v0.3.2/go.mod h1:MgQIvLx9mhOoScMJnSFvXuqbAQVIwWtLJ862K1jRvR8=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-redis/redis/v7 v7.2.0 h1:CrCexy/jYWZjW0AyVoHlcJUeZN19VWlbepTh1Vq6dJs=
Expand Down
8 changes: 7 additions & 1 deletion stores/redisstore/store.go
Expand Up @@ -7,6 +7,7 @@ package redisstore
import (
"time"

"github.com/clevergo/captchas"
"github.com/go-redis/redis/v7"
)

Expand Down Expand Up @@ -67,11 +68,16 @@ func (s *Store) Get(id string, clear bool) (string, error) {
return "", err
}
val, err := get.Result()
isNil := false
if err != nil {
isNil = err == redis.Nil
if isNil {
return "", captchas.ErrCaptchaIncorrect
}
return "", err
}

if clear {
if clear && !isNil {
if _, err = del.Result(); err != nil {
return "", err
}
Expand Down

0 comments on commit 0870ae0

Please sign in to comment.