-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredis_test.go
More file actions
52 lines (47 loc) · 854 Bytes
/
redis_test.go
File metadata and controls
52 lines (47 loc) · 854 Bytes
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 redis
import (
"fmt"
"testing"
"time"
)
func TestRedisStore(t *testing.T) {
r, err := NewRediStore(10, "tcp", "127.0.0.1:6379", "")
if err != nil {
t.Fatal(err)
}
defer r.Close()
id := 1
if err := r.PutJSON("testing", id, 60*time.Second); err != nil {
t.Fatal(err)
}
outId := 0
if err := r.ScanJSON("testing", &outId); err != nil {
t.Fatal(err)
}
if id != outId {
t.Fatal(id, outId)
}
nextCursor := int64(0)
for {
nextCursor, keys, err := r.ScanKey(nextCursor, "test*", 100)
if err != nil {
t.Fatal(err)
}
for _, k := range keys {
fmt.Println(string(k))
}
if nextCursor == 0 {
break
}
}
if err := r.Delete("testing"); err != nil {
t.Fatal(err)
}
if err := r.ScanJSON("testing", &outId); err != nil {
if err != ErrNil {
t.Fatal(err)
}
} else {
t.Fatal("found data", outId)
}
}