first commit
This commit is contained in:
commit
0c9c9710ce
8 changed files with 711 additions and 0 deletions
117
producer.go
Normal file
117
producer.go
Normal file
|
@ -0,0 +1,117 @@
|
|||
// iterator
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/garyburd/redigo/redis"
|
||||
)
|
||||
|
||||
type userQuota struct {
|
||||
user string
|
||||
storage int
|
||||
messages int
|
||||
}
|
||||
|
||||
type produced struct {
|
||||
user string
|
||||
logins []string
|
||||
}
|
||||
|
||||
func producer() {
|
||||
conn := dbs.rdb.Get()
|
||||
defer conn.Close()
|
||||
|
||||
keys, err := redis.Strings(conn.Do("KEYS", "*"))
|
||||
|
||||
if err != nil {
|
||||
if opts.Debug {
|
||||
fmt.Printf("Keys error: %v\n", err)
|
||||
}
|
||||
log.Printf("Keys error: %v\n", err)
|
||||
exit()
|
||||
}
|
||||
|
||||
users := make(map[string]bool)
|
||||
|
||||
for _, key := range keys {
|
||||
user := key[:strings.Index(key, "@")]
|
||||
users[user] = true
|
||||
}
|
||||
|
||||
uq := make([]userQuota, 0)
|
||||
max := 0
|
||||
|
||||
for key, _ := range users {
|
||||
|
||||
if !loop {
|
||||
break
|
||||
}
|
||||
|
||||
// wg.Wait()
|
||||
status = _Producer
|
||||
|
||||
start := time.Now()
|
||||
if opts.Test {
|
||||
fmt.Printf("MGET: %s (%d)\n", key, max)
|
||||
}
|
||||
// estrae un userid dalla lista degli utenti che hanno fatto login
|
||||
quota, err := redis.Strings(conn.Do("mget", fmt.Sprintf("%s@tiscali.it/quota/messages", key), fmt.Sprintf("%s@tiscali.it/quota/storage", key)))
|
||||
// se non ci sono piu' userid esce
|
||||
if err != nil {
|
||||
if opts.Debug {
|
||||
fmt.Printf("MGET err: %v\n", err)
|
||||
}
|
||||
log.Printf("MGET err: %v\n", err)
|
||||
continue
|
||||
}
|
||||
|
||||
counter <- Counterchan{
|
||||
tipo: "user",
|
||||
val: 1,
|
||||
}
|
||||
|
||||
msg, err := strconv.Atoi(quota[0])
|
||||
if err != nil {
|
||||
msg = 0
|
||||
}
|
||||
store, err := strconv.Atoi(quota[1])
|
||||
if err != nil {
|
||||
store = 0
|
||||
}
|
||||
|
||||
uq = append(uq, userQuota{
|
||||
user: key,
|
||||
messages: msg,
|
||||
storage: store,
|
||||
})
|
||||
|
||||
if opts.Test {
|
||||
fmt.Printf("User: %s - %+v\n", key, quota)
|
||||
}
|
||||
|
||||
if max >= opts.MaxBulk {
|
||||
if opts.Debug {
|
||||
fmt.Printf("\nPROD: %+v\n", time.Since(start))
|
||||
}
|
||||
|
||||
// wg.Add(1)
|
||||
// counter <- Counterchan{
|
||||
// tipo: "wg",
|
||||
// val: 1,
|
||||
// }
|
||||
|
||||
consume <- uq
|
||||
uq = make([]userQuota, 0)
|
||||
max = 0
|
||||
}
|
||||
|
||||
max += 1
|
||||
}
|
||||
|
||||
done <- true
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue