1
0
Fork 0
mirror of https://github.com/Luzifer/cloudkeys-go.git synced 2024-11-08 22:20:05 +00:00
cloudkeys-go/vendor/github.com/xuyu/goredis/transactions_test.go

70 lines
1.3 KiB
Go

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)
}
}