-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfreq_test.go
52 lines (42 loc) · 887 Bytes
/
freq_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package tool
import (
"context"
"fmt"
"sync"
"testing"
"github.com/neo532/gofr/tool"
)
var (
freq *tool.Freq
)
func init() {
freq = tool.NewFreq(rdb)
freq.Timezone("Local")
}
func TestFreq(t *testing.T) {
c := context.Background()
preKey := "user.test"
rule := []tool.FreqRule{
tool.FreqRule{Duri: "10", Times: 2},
}
count := 10000
var wg sync.WaitGroup
wg.Add(count)
for i := 0; i < count; i++ {
go func() {
defer wg.Done()
ok, err := freq.IncrCheck(c, preKey, rule...)
if err == nil && ok {
fmt.Println(fmt.Sprintf("%s\t:Biz run!", t.Name()))
}
}()
}
wg.Wait()
var err error
var b bool
b, err = freq.IncrCheck(c, preKey, rule...)
fmt.Println(fmt.Sprintf("%s\t:incrCheck!,%v,%v", t.Name(), b, err))
var times int64
times, err = freq.Get(c, preKey, rule...)
fmt.Println(fmt.Sprintf("%s\t:freqGet!,%d,%v", t.Name(), times, err))
}