Score
0
Watch 16 Star 50 Fork 2

piaohao / godisGoMIT

Join us
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
godis 是一个 golang 实现的 redis 客户端,参考 jedis 实现。godis 实现了几乎所有的 redis 命令,包括单机命令,集群命令,管道命令和事物命令等 spread retract

Clone or download
pool_test.go 1.55 KB
Copy Edit Web IDE Raw Blame History
piaohao authored 2019-07-03 18:42 . 1.add more args of poolconfig;
package godis
import (
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestPool_Basic(t *testing.T) {
pool := NewPool(&PoolConfig{
MaxTotal: 4,
MaxIdle: 2,
MinIdle: 2,
TestOnBorrow: true,
}, &Option{
Host: "localhost",
Port: 6379,
ConnectionTimeout: 2 * time.Second,
SoTimeout: 2 * time.Second,
Password: "",
Db: 0,
})
redis, e := pool.GetResource()
assert.Nil(t, e)
s, e := redis.Echo("godis")
assert.Nil(t, e)
assert.Equal(t, "godis", s)
e = pool.returnResourceObject(redis)
assert.Nil(t, e)
s, e = redis.Echo("godis")
assert.Nil(t, e)
assert.Equal(t, "godis", s)
redis1, e := pool.GetResource()
assert.Nil(t, e)
e = pool.returnBrokenResourceObject(redis1)
assert.Nil(t, e)
s, e = redis1.Echo("godis")
assert.NotNil(t, e)
assert.Equal(t, "", s)
pool.internalPool.Clear(nil)
redis3, e := pool.GetResource()
assert.Nil(t, e)
pool.Destroy()
s, e = redis3.Echo("godis")
assert.Nil(t, e)
assert.Equal(t, "godis", s)
_, e = pool.GetResource()
assert.NotNil(t, e)
}
func TestPool_Basic2(t *testing.T) {
pool := NewPool(&PoolConfig{
MaxTotal: 4,
MaxIdle: 2,
MinIdle: 2,
MinEvictableIdleTime: 10,
TestOnBorrow: true,
}, &Option{
Host: "localhost",
Port: 6379,
ConnectionTimeout: 2 * time.Second,
SoTimeout: 2 * time.Second,
Password: "123456",
Db: 0,
})
_, e := pool.GetResource()
assert.NotNil(t, e) //auth error
}

Comment ( 0 )

Sign in for post a comment

Go
1
https://gitee.com/piaohao/godis.git
git@gitee.com:piaohao/godis.git
piaohao
godis
godis
master

Help Search