-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathtransactions_test.go
70 lines (65 loc) · 1.3 KB
/
transactions_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
package goredis
import (
"testing"
)
func TestTransaction(t *testing.T) {
transaction, err := r.Transaction()
if err != nil {
t.Error(err)
}
defer transaction.Close()
if err := transaction.Command("DEL", "key"); err != nil {
t.Error(err)
}
if err := transaction.Command("SET", "key", 1); err != nil {
t.Error(err)
}
if err := transaction.Command("INCR", "key"); err != nil {
t.Error(err)
}
if err := transaction.Command("GET", "key"); err != nil {
t.Error(err)
}
result, err := transaction.Exec()
if err != nil {
t.Error(err)
}
if len(result) != 4 {
t.Fail()
}
if s, err := result[3].StringValue(); err != nil || s != "2" {
t.Fail()
}
}
func TestWatch(t *testing.T) {
transaction, err := r.Transaction()
if err != nil {
t.Error(err)
}
defer transaction.Close()
if err := transaction.Watch("key"); err != nil {
t.Error(err)
}
}
func TestUnWatch(t *testing.T) {
transaction, err := r.Transaction()
if err != nil {
t.Error(err)
}
defer transaction.Close()
transaction.Watch("key")
if err := transaction.UnWatch(); err != nil {
t.Error(err)
}
}
func TestDiscard(t *testing.T) {
transaction, err := r.Transaction()
if err != nil {
t.Error(err)
}
defer transaction.Close()
transaction.Command("SET", "KEY", 1)
if transaction.Discard(); err != nil {
t.Error(err)
}
}