-
-
Save wicoady1/d85ec8accd0513ce6d1ae43f0b6360a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//check https://github.com/wicoady1/redissimulation/blob/master/handler/service.response.go for full code | |
//validateResponse validate response, hold multiple / spam response with redis | |
func (m *Module) validateResponse(input string) error { | |
//let's use "anti-spam:test" key as redis key | |
key := fmt.Sprintf("anti-spam:%s", input) | |
//check key, is it exist? | |
value, err := m.Redis.Get(key) | |
if err != nil { | |
log.Fatal(err) | |
} | |
//value not nil, means the redis is already exists | |
//therefore return error | |
if value != nil { | |
return fmt.Errorf("Value Exists, Please Wait") | |
} | |
//if there is no redis key | |
//set new key with 10 second expiration time | |
err = m.Redis.Setex(key, 10, "1") | |
if err != nil { | |
return err | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment