diff --git a/src/redisx.c b/src/redisx.c index 448fb06..df1500f 100644 --- a/src/redisx.c +++ b/src/redisx.c @@ -476,7 +476,6 @@ static void rAffirmDB(Redis *redis) { * @param confirm Whether to wait for confirmation from Redis, and check the response. * @return X_SUCCESS (0) if successful, or * X_NULL if the redis argument is NULL, - * X_NO_INIT if the redis instance is not connected, * X_INCOMPLETE if there is an active subscription channel that cannot be switched or * one of the channels could not confirm the switch, or * else another error code (<0) from redisx.h / xchange.h. @@ -492,15 +491,17 @@ int redisxSelectDB(Redis *redis, int idx, boolean confirm) { int status = X_SUCCESS; if(!redis) return redisxError(funcName, X_NULL); - if(!redisxIsConnected(redis)) return redisxError(funcName, X_NO_INIT); p = (RedisPrivate *) redis->priv; - if(p->dbIndex == idx) return X_SUCCESS; - redisxAddConnectHook(redis, rAffirmDB); p->dbIndex = idx; + if(idx) redisxAddConnectHook(redis, rAffirmDB); + else redisxRemoveConnectHook(redis, rAffirmDB); + + if(!redisxIsConnected(redis)) return X_SUCCESS; + for(c = 0; c < REDISX_CHANNELS; c++) { RedisClient *cl = redisxGetClient(redis, c); int s = redisxLockEnabled(cl);