Fix db selection. Fixes #31.

This commit is contained in:
Vladimir Mihailenco 2014-07-08 11:24:19 +03:00
parent dc9bffa57d
commit 537971dca1
2 changed files with 15 additions and 1 deletions

View File

@ -40,7 +40,7 @@ func (c *baseClient) conn() (*conn, error) {
}
func (c *baseClient) initConn(cn *conn) error {
if c.opt.Password == "" || c.opt.DB == 0 {
if c.opt.Password == "" && c.opt.DB == 0 {
return nil
}

View File

@ -150,6 +150,20 @@ func (t *RedisConnectorTest) TestIdleTimeout(c *C) {
}
}
func (t *RedisConnectorTest) TestSelectDb(c *C) {
client1 := redis.NewTCPClient(&redis.Options{
Addr: redisAddr,
DB: 1,
})
c.Assert(client1.Set("key", "db1").Err(), IsNil)
client2 := redis.NewTCPClient(&redis.Options{
Addr: redisAddr,
DB: 2,
})
c.Assert(client2.Get("key").Err(), Equals, redis.Nil)
}
//------------------------------------------------------------------------------
type RedisConnPoolTest struct {