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 c4e9d76
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 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 @@ -485,22 +484,22 @@ static void rAffirmDB(Redis *redis) {
* @sa redisxLockEnabled()
*/
int redisxSelectDB(Redis *redis, int idx, boolean confirm) {
static const char *funcName = "redisxSelectDB()";

RedisPrivate *p;
enum redisx_channel c;
int status = X_SUCCESS;

if(!redis) return redisxError(funcName, X_NULL);
if(!redisxIsConnected(redis)) return redisxError(funcName, X_NO_INIT);
if(!redis) return redisxError("redisxSelectDB()", X_NULL);

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 c4e9d76

Please sign in to comment.