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
|
user string
|
||||||
error bool
|
error bool
|
||||||
logins []string
|
logins []string
|
||||||
|
empty bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func contains(s []Ips, e string) bool {
|
func contains(s []Ips, e string) bool {
|
||||||
|
@ -100,6 +101,10 @@ func consumer(id int) {
|
||||||
|
|
||||||
count.AddLog(len(prod.logins))
|
count.AddLog(len(prod.logins))
|
||||||
|
|
||||||
|
if opts.MaxLogins != -1 && len(prod.logins) < opts.MaxLogins {
|
||||||
|
cons.empty = true
|
||||||
|
}
|
||||||
|
|
||||||
if opts.Debug {
|
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())
|
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 (
|
const (
|
||||||
_VERSION = "v2.7.2"
|
_VERSION = "v2.8.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -20,6 +20,7 @@ type Options struct {
|
||||||
LogFile string
|
LogFile string
|
||||||
ConfigFile string
|
ConfigFile string
|
||||||
Timeout time.Duration
|
Timeout time.Duration
|
||||||
|
MaxLogins int
|
||||||
Debug bool
|
Debug bool
|
||||||
Version bool
|
Version bool
|
||||||
Concurrent int
|
Concurrent int
|
||||||
|
@ -33,8 +34,9 @@ type Options struct {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
opts = Options{
|
opts = Options{
|
||||||
RedisTTL: time.Hour * 11688, // 16 mesi
|
RedisTTL: time.Hour * 11688, // 16 mesi
|
||||||
LogFile: "log/llmongo.log",
|
LogFile: "log/llmongo.log",
|
||||||
|
MaxLogins: -1,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -61,6 +63,7 @@ func init() {
|
||||||
flag.StringVar(&dbs.Database, "d", dbs.Database, "Mongodb Database")
|
flag.StringVar(&dbs.Database, "d", dbs.Database, "Mongodb Database")
|
||||||
flag.StringVar(&dbs.RedisUri, "r", dbs.RedisUri, "Redis")
|
flag.StringVar(&dbs.RedisUri, "r", dbs.RedisUri, "Redis")
|
||||||
flag.StringVar(&opts.LogFile, "l", opts.LogFile, "Logs filename")
|
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.DurationVar(&opts.RedisTTL, "t", opts.RedisTTL, "Redis keys TTL")
|
||||||
flag.BoolVar(&opts.Version, "v", false, "Version")
|
flag.BoolVar(&opts.Version, "v", false, "Version")
|
||||||
flag.DurationVar(&opts.Timeout, "T", 0, "Running timeout")
|
flag.DurationVar(&opts.Timeout, "T", 0, "Running timeout")
|
||||||
|
|
|
@ -3,9 +3,11 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/garyburd/redigo/redis"
|
|
||||||
"log"
|
"log"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/garyburd/redigo/redis"
|
||||||
)
|
)
|
||||||
|
|
||||||
type produced struct {
|
type produced struct {
|
||||||
|
@ -38,7 +40,7 @@ func producer(id int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// estrae tutti i login dell'utente "user"
|
// 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 err != nil {
|
||||||
if opts.Debug {
|
if opts.Debug {
|
||||||
fmt.Printf("LRANGE: %+v - %+v\n", err, logs)
|
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
|
// cancella da Redis la riga di login inserita partendo da 1
|
||||||
conn.Send("lrem", rem.user, "1", login)
|
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 {
|
if opts.Debug {
|
||||||
fmt.Printf("SADD (%d): %s\n", id, rem.user)
|
fmt.Printf("SADD (%d): %s\n", id, rem.user)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue