package redisdb

import (
	"fmt"
	"testing"
)

func TestRedis(t *testing.T) {
	r := &Redis{
		Host:    "127.0.0.1",
		Port:    6379,
		MaxIdle: 3,
	}
	err := r.Init()
	if err != nil {
		t.Error(err)
	}
	c := r.Pool.Get()
	defer c.Close()
	_, err = c.Do("SETEX", "foo1", 100, "bar")
	if err != nil {
		t.Error(err)
	}
}
func TestPipleline(t *testing.T) {
	r := &Redis{
		Host:    "127.0.0.1",
		Port:    6379,
		MaxIdle: 3,
	}
	err := r.Init()
	if err != nil {
		t.Error(err)
	}
	c := r.Pool.Get()
	defer c.Close()
	c.Send("SET", "foo", "bar")
	c.Send("GET", "foo")
	c.Flush()
	c.Receive()           // reply from SET
	v, err := c.Receive() // reply from GET
	if err != nil {
		t.Error(err)
	}
	fmt.Println(string(v.([]uint8)))

	c.Send("MULTI")
	c.Send("INCR", "foo2")
	c.Send("INCR", "bar2")
	c.Send("SET", "foo", "bar")
	c.Send("GET", "foo")
	v, err = c.Do("EXEC")
	fmt.Println(v, err)
}
