1
0
mirror of https://github.com/Luzifer/cloudkeys-go.git synced 2024-09-20 08:02:57 +00:00
cloudkeys-go/vendor/github.com/xuyu/goredis/transactions_test.go

71 lines
1.3 KiB
Go
Raw Normal View History

2015-07-30 15:43:22 +00:00
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)
}
}