Browse Source

* better error handling in source/redis & backend/redis

master
Alex 'AdUser' Z 8 years ago
parent
commit
d11adf90e7
  1. 16
      src/backends/redis.c
  2. 9
      src/sources/redis.c

16
src/backends/redis.c

@ -56,7 +56,8 @@ redis_connect(cfg_t *cfg) {
break;
}
if (cfg->password[0]) {
reply = redisCommand(conn, "AUTH %s", cfg->password);
if ((reply = redisCommand(conn, "AUTH %s", cfg->password)) == NULL)
break;
if (reply->type == REDIS_REPLY_ERROR) {
snprintf(cfg->error, sizeof(cfg->error), "auth error: %s", reply->str);
break;
@ -64,7 +65,8 @@ redis_connect(cfg_t *cfg) {
freeReplyObject(reply);
}
if (cfg->database) {
reply = redisCommand(conn, "SELECT %d", cfg->database);
if ((reply = redisCommand(conn, "SELECT %d", cfg->database)) == NULL)
break;
if (reply->type == REDIS_REPLY_ERROR) {
snprintf(cfg->error, sizeof(cfg->error), "auth error: %s", reply->str);
break;
@ -193,14 +195,16 @@ ban(cfg_t *cfg, const char *ip) {
redisReply *reply;
do {
reply = redisCommand(cfg->conn, "HINCRBY %s %s %d", cfg->hash, ip, 1);
if (reply && reply->type == REDIS_REPLY_ERROR) {
if ((reply = redisCommand(cfg->conn, "HINCRBY %s %s %d", cfg->hash, ip, 1)) == NULL)
break;
if (reply->type == REDIS_REPLY_ERROR) {
snprintf(cfg->error, sizeof(cfg->error), "HINCRBY: %s", reply->str);
break;
}
freeReplyObject(reply);
reply = redisCommand(cfg->conn, "PUBLISH %s %s", cfg->hash, ip);
if (reply && reply->type == REDIS_REPLY_ERROR) {
if ((reply = redisCommand(cfg->conn, "PUBLISH %s %s", cfg->hash, ip)) == NULL)
break;
if (reply->type == REDIS_REPLY_ERROR) {
snprintf(cfg->error, sizeof(cfg->error), "PUBLISH: %s", reply->str);
break;
}

9
src/sources/redis.c

@ -51,7 +51,8 @@ redis_connect(cfg_t *cfg) {
break;
}
if (cfg->password[0]) {
reply = redisCommand(conn, "AUTH %s", cfg->password);
if ((reply = redisCommand(conn, "AUTH %s", cfg->password)) == NULL)
break;
if (reply->type == REDIS_REPLY_ERROR) {
snprintf(cfg->error, sizeof(cfg->error), "auth error: %s", reply->str);
break;
@ -59,7 +60,8 @@ redis_connect(cfg_t *cfg) {
freeReplyObject(reply);
}
if (cfg->database) {
reply = redisCommand(conn, "SELECT %d", cfg->database);
if ((reply = redisCommand(conn, "SELECT %d", cfg->database)) == NULL)
break;
if (reply->type == REDIS_REPLY_ERROR) {
snprintf(cfg->error, sizeof(cfg->error), "auth error: %s", reply->str);
break;
@ -72,7 +74,8 @@ redis_connect(cfg_t *cfg) {
strlcpy(cfg->error, "can't enable nonblocking mode", sizeof(cfg->error));
break;
}
reply = redisCommand(conn, "SUBSCRIBE %s", cfg->hash);
if ((reply = redisCommand(conn, "SUBSCRIBE %s", cfg->hash)) == NULL)
break;
if (reply->type == REDIS_REPLY_ERROR) {
snprintf(cfg->error, sizeof(cfg->error), "can't subscribe: %s", reply->str);
break;

Loading…
Cancel
Save