Created
August 20, 2018 22:30
-
-
Save pzillmann/f124f7c1932093c976ed3727615cc07a to your computer and use it in GitHub Desktop.
Remove rspamd history values from redis database after x hours
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
package main | |
import ( | |
"encoding/json" | |
"os" | |
"time" | |
"github.com/mediocregopher/radix.v2/redis" | |
) | |
func main() { | |
const dataset string = "rs_historyHOSTNAME" | |
const hours int = 24 | |
var j interface{} | |
var r *redis.Resp | |
client, err := redis.Dial("unix", "/var/run/redis/redis.sock") | |
if err != nil { | |
panic(err) | |
} | |
for { | |
r = client.Cmd("lindex", dataset, "-1") | |
if r.Err != nil { | |
panic(r.Err) | |
} | |
b, err := r.Bytes() | |
err = json.Unmarshal(b, &j) | |
if err != nil { | |
os.Exit(1) | |
} | |
j_ta := j.(map[string]interface{}) | |
timestamp_int := (int64)(j_ta["unix_time"].(float64)) | |
mailtime := time.Unix(timestamp_int, 0).Add(time.Duration(hours) * time.Hour) | |
if mailtime.Before(time.Now()) { | |
if client.Cmd("RPOP", dataset).Err != nil { | |
os.Exit(3) | |
} | |
} else { | |
break | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment