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