package CaptchaController import ( "context" "dsSzxy/Utils/RedisUtil" "fmt" "time" ) var ctx = context.Background() const CAPTCHA = "captcha:" type RedisStore struct { } // Set set a capt func (r RedisStore) Set(id string, value string) { key := CAPTCHA + id RedisUtil.SET(key, value, time.Minute*2) } // Get get a capt func (r RedisStore) Get(id string, clear bool) string { key := CAPTCHA + id val, err := RedisUtil.GET(key) if err != nil { fmt.Println(err) return "" } if clear { RedisUtil.DEL(key) } return val } // Verify verify a capt func (r RedisStore) Verify(id, answer string, clear bool) bool { v := RedisStore{}.Get(id, clear) return v == answer }