aggiunta l'opzione per limitare il numero max di logins da gestire per utente
This commit is contained in:
parent
c4064e033e
commit
79f1ce80e3
5 changed files with 18 additions and 6 deletions
|
@ -15,6 +15,7 @@ type consumed struct {
|
|||
user string
|
||||
error bool
|
||||
logins []string
|
||||
empty bool
|
||||
}
|
||||
|
||||
func contains(s []Ips, e string) bool {
|
||||
|
@ -100,6 +101,10 @@ func consumer(id int) {
|
|||
|
||||
count.AddLog(len(prod.logins))
|
||||
|
||||
if opts.MaxLogins != -1 && len(prod.logins) < opts.MaxLogins {
|
||||
cons.empty = true
|
||||
}
|
||||
|
||||
if opts.Debug {
|
||||
fmt.Printf("CONS (%d): user=%s logins=%d in %v - active=%d\n", id, prod.user, len(prod.logins), time.Since(start), dbs.rdb.ActiveCount())
|
||||
}
|
||||
|
|
2
main.go
2
main.go
|
@ -11,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
_VERSION = "v2.7.2"
|
||||
_VERSION = "v2.8.0"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -20,6 +20,7 @@ type Options struct {
|
|||
LogFile string
|
||||
ConfigFile string
|
||||
Timeout time.Duration
|
||||
MaxLogins int
|
||||
Debug bool
|
||||
Version bool
|
||||
Concurrent int
|
||||
|
@ -33,8 +34,9 @@ type Options struct {
|
|||
|
||||
var (
|
||||
opts = Options{
|
||||
RedisTTL: time.Hour * 11688, // 16 mesi
|
||||
LogFile: "log/llmongo.log",
|
||||
RedisTTL: time.Hour * 11688, // 16 mesi
|
||||
LogFile: "log/llmongo.log",
|
||||
MaxLogins: -1,
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -61,6 +63,7 @@ func init() {
|
|||
flag.StringVar(&dbs.Database, "d", dbs.Database, "Mongodb Database")
|
||||
flag.StringVar(&dbs.RedisUri, "r", dbs.RedisUri, "Redis")
|
||||
flag.StringVar(&opts.LogFile, "l", opts.LogFile, "Logs filename")
|
||||
flag.IntVar(&opts.MaxLogins, "L", opts.MaxLogins, "Max lastlogins")
|
||||
flag.DurationVar(&opts.RedisTTL, "t", opts.RedisTTL, "Redis keys TTL")
|
||||
flag.BoolVar(&opts.Version, "v", false, "Version")
|
||||
flag.DurationVar(&opts.Timeout, "T", 0, "Running timeout")
|
||||
|
|
|
@ -3,9 +3,11 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/garyburd/redigo/redis"
|
||||
"log"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/garyburd/redigo/redis"
|
||||
)
|
||||
|
||||
type produced struct {
|
||||
|
@ -38,7 +40,7 @@ func producer(id int) {
|
|||
}
|
||||
|
||||
// estrae tutti i login dell'utente "user"
|
||||
logs, err := redis.Strings(conn.Do("lrange", user, "1", "-1"))
|
||||
logs, err := redis.Strings(conn.Do("lrange", user, "1", strconv.Itoa(opts.MaxLogins)))
|
||||
if err != nil {
|
||||
if opts.Debug {
|
||||
fmt.Printf("LRANGE: %+v - %+v\n", err, logs)
|
||||
|
|
|
@ -22,7 +22,9 @@ func remover(id int) {
|
|||
// cancella da Redis la riga di login inserita partendo da 1
|
||||
conn.Send("lrem", rem.user, "1", login)
|
||||
}
|
||||
if rem.error {
|
||||
|
||||
// se ci sono errori o non e' vuota la lista di logins reinserisce lo user
|
||||
if rem.error || !rem.empty {
|
||||
if opts.Debug {
|
||||
fmt.Printf("SADD (%d): %s\n", id, rem.user)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue