rewrite redis communication

This commit is contained in:
Max Lerebourg
2022-11-11 00:09:06 +01:00
parent 4a5f1eca6a
commit 18f68de196
4 changed files with 73 additions and 164 deletions
+6 -1
View File
@@ -19,6 +19,8 @@ var redis simpleredis.SimpleRedis
var redisEnabled = false
// CLASSIC
func getDecisionLocalCache(clientIP string) (bool, error) {
banned, isCached := cache.Get(clientIP)
bannedString, isValid := banned.(string)
@@ -36,6 +38,8 @@ func deleteDecisionLocalCache(clientIP string) {
cache.Del(clientIP)
}
// REDIS
func getDecisionRedisCache(clientIP string) (bool, error) {
banned, err := redis.Get(clientIP)
bannedString := string(banned)
@@ -53,6 +57,7 @@ func deleteDecisionRedisCache(clientIP string) {
redis.Del(clientIP)
}
// DeleteDecision delete decision in cache
func DeleteDecision(clientIP string) {
if redisEnabled {
deleteDecisionRedisCache(clientIP)
@@ -89,5 +94,5 @@ func SetDecision(clientIP string, isBanned bool, duration int64) {
func InitRedisClient(host string) {
redisEnabled = true
redis.Init(host)
logger.Debug("connect to redis")
logger.Debug("Redis initialized")
}