-
Notifications
You must be signed in to change notification settings - Fork 0
/
beegofreecache_test.go
122 lines (105 loc) · 2.59 KB
/
beegofreecache_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package beegofreecache
import "testing"
import (
"github.com/astaxie/beego/cache"
"time"
. "beegofreecache"
"strconv"
)
var bm, err = cache.NewCache("beegofreecache", `{"size":64}`)
func TestBeeFreeCacheGP(t *testing.T) {
if err!=nil {
println(err.Error())
}
key:="key"
bm.Put(key,1200,10*time.Second)
val:=bm.Get(key)
var ii int
GobDecode(val.([]byte),&ii)
println(val,ii)
}
func TestBeeFreeCacheDel(t *testing.T) {
//var bm, err = cache.NewCache("beegofreecache", `{"size":64}`)
if err!=nil {
println(err.Error())
}
key:="key"
bm.Put(key,1200,10*time.Second)
val:=bm.Get(key)
var ii int
GobDecode(val.([]byte),&ii)
println(val,ii)
bm.Delete(key)
val=bm.Get(key)
println(val)
}
func TestBeeFreeCacheGetMu(t *testing.T) {
//var bm, err = cache.NewCache("beegofreecache", `{"size":64}`)
if err!=nil {
println(err.Error())
}
key:="key"
for i:=0;i<10 ;i++ {
bm.Put(key+strconv.Itoa(i),i*23,10*time.Second)
}
vals:=bm.GetMulti([]string{"key0","key1","key2","key3"})
for _,val:=range vals{
var ii int
GobDecode(val.([]byte),&ii)
println(val,ii)
}
}
func TestBeeFreeCacheCr(t *testing.T) {
// var bm, err = cache.NewCache("beegofreecache", `{"size":64}`)
if err!=nil {
println(err.Error())
}
key:="key"
bm.Put(key,int64(0),10*time.Second)
val:=bm.Get(key)
var ii int64
GobDecode(val.([]byte),&ii)
println("get",val,ii)
err=bm.Incr(key)
val=bm.Get(key)
GobDecode(val.([]byte),&ii)
println("Incr",err,val,ii)
bm.Decr(key)
val=bm.Get(key)
GobDecode(val.([]byte),&ii)
println(val,ii)
}
func TestBeeFreeCacheEx(t *testing.T) {
key:="exist"
bm.Put(key,"TestBeeFreeCacheEx",10*time.Second)
b:=bm.IsExist(key)
if b{
val:=bm.Get(key)
var ii string
GobDecode(val.([]byte),&ii)
println("get",val,ii)
}
b=bm.IsExist("noexist")
println("noexist",b)
}
func TestBeeFreeCacheClear(t *testing.T) {
key:="key"
for i:=0;i<10 ;i++ {
bm.Put(key+strconv.Itoa(i),i*23,10*time.Second)
}
for i:=0;i<10 ;i++ {
println(key+strconv.Itoa(i),bm.IsExist(key+strconv.Itoa(i)))
}
bm.ClearAll()
for i:=0;i<10 ;i++ {
println(key+strconv.Itoa(i),bm.IsExist(key+strconv.Itoa(i)))
}
}
func TestBeeFreeCacheGetValue(t *testing.T) {
free:= NewFree(16)
key:="key"
free.Put(key,1200,10*time.Second)
var ii int
val:=free.GetValue(key,&ii)
println("GetValue",val,ii)
}