Skip to content

Commit

Permalink
tweak selectDB function
Browse files Browse the repository at this point in the history
  • Loading branch information
attipaci committed Sep 4, 2024
1 parent f9f5a39 commit 7c6dc74
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/redisx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand Down

0 comments on commit 7c6dc74

Please sign in to comment.