-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCacheChannel_test.go
More file actions
67 lines (55 loc) · 1.47 KB
/
Copy pathCacheChannel_test.go
File metadata and controls
67 lines (55 loc) · 1.47 KB
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
package go2cache
import (
"github.com/garyburd/redigo/redis"
"log"
"strconv"
"testing"
"time"
)
func TestGetCacheChannel(t *testing.T) {
cacheChannel := GetCacheChannel()
cache := cacheChannel.GetRedisCache("user_region")
var key = time.Now().Format("2006-01-02 15:04:05")
var filed = key
v := cache.HincrBy(key, filed, 1)
log.Printf("hincyBy v:%d", v)
hget, _ := redis.Int(cache.Hget(key, filed), nil)
log.Printf("Hget v:%d", hget)
intMap := cache.HgetAllIntMap(key)
log.Printf("HgetAllIntMap:%d", intMap[key])
for k := range intMap {
delete(intMap, k)
}
cache.Hset(key, "2", "this is test")
vv := cache.Hget(key, "2") // Get bytes array
obj := cache.Hdel(key, "2")
vv = cache.Hget(key, "2") // Get bytes array
log.Printf("%s", obj)
cache.Hset(key, "2", "this is test")
vv = cache.Hget(key, "2") // Get bytes array
log.Printf("hset value:%s", string(vv.([]byte)))
cache.HgetAllBytesMap(key)
l := cache.Hlen(key)
log.Printf("len:%d", l)
key = "key2"
cache.SAdd(key, 1)
cache.SAdd(key, 2)
setLen, e := redis.Int64(cache.Do("SCARD", "go2cache:user_region:key2"))
if e != nil {
log.Fatal(e.Error())
}
log.Printf("scard len :%d", setLen)
bb := cache.Sismember(key, 1)
log.Printf("Sismember:%t", bb)
smembers := cache.Smembers(key)
for _, dd := range smembers {
x, _ := strconv.Atoi(string(dd.([]byte)))
log.Printf("data:%d", x)
}
sa := cache.SmembersString(key)
for _, v := range *sa {
log.Printf("value %s", v)
}
sa = nil
cache.Del(key)
}