forked from mirror/redis
Fix db selection. Fixes #31.
This commit is contained in:
parent
dc9bffa57d
commit
537971dca1
2
redis.go
2
redis.go
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue