-
Notifications
You must be signed in to change notification settings - Fork 4
/
db-redis_test.go
69 lines (58 loc) · 1.5 KB
/
db-redis_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
package Figo
import (
"github.com/quexer/utee"
"log"
"testing"
"time"
)
func TestRedisSetAndGet(t *testing.T) {
rp := RedisPool("localhost:6379", "")
RedisSet(rp, "FOO", "BAR")
v, err := RedisGet(rp, "FOO")
utee.Chk(err)
log.Println(TpString(v))
}
func TestRedisSetEx(t *testing.T) {
rp := RedisPool("localhost:6379", "")
RedisSetEx(rp, "FOO", "BAR", 10)
v, err := RedisGet(rp, "FOO")
utee.Chk(err)
log.Println(TpString(v))
time.Sleep(time.Duration(11) * time.Second)
v, err = RedisGet(rp, "FOO")
utee.Chk(err)
log.Println(TpString(v))
}
func TestRedisBitmap(t *testing.T) {
rp := RedisPool("localhost:6379", "")
err := RedisSetbit(rp, "FOO", 1)
log.Println("set bit ", err)
err = RedisSetbit(rp, "FOO1", 2)
log.Println("set bit ", err)
exist, err := RedisGetbit(rp, "FOO", 1)
log.Println("get bit exist", exist, "err", err)
c, err := RedisBitcount(rp, "FOO")
log.Println("count bit ", c, "err", err)
err = RedisBitop(rp, "or", "dest", "FOO", "FOO1")
log.Println("bitop or ", "err", err)
err = RedisBitop(rp, "and", "dest1", "FOO", "FOO1", "FOO2")
log.Println("bitop and ", "err", err)
}
func Test_r_Rpush(t *testing.T){
rp := RedisPool("localhost:6379", "")
k := "figo"
RedisRpush(rp, k,"hello")
RedisRpush(rp, k,"world")
RedisRpush(rp, k,"how")
RedisRpush(rp, k,"r")
RedisRpush(rp, k,"u")
log.Println(RedisLlen(rp, k))
v,err:=RedisLpop(rp, k)
utee.Chk(err)
log.Println(v)
l,err:=RedisLlen(rp, k)
log.Println("@len:",l)
for i:=0;i<l;i++ {
log.Println(RedisLindex(rp,k,i))
}
}