/* * Query the redis database */ int rlm_redis_query(REDISSOCK **dissocket_p, REDIS_INST *inst, const char *query, REQUEST *request) { REDISSOCK *dissocket; int argc; const char *argv[MAX_REDIS_ARGS]; char argv_buf[MAX_QUERY_LEN]; if (!query || !*query || !inst || !dissocket_p) { return -1; } argc = rad_expand_xlat(request, query, MAX_REDIS_ARGS, argv, 0, sizeof(argv_buf), argv_buf); if (argc <= 0) return -1; dissocket = *dissocket_p; DEBUG2("executing %s ...", argv[0]); dissocket->reply = redisCommandArgv(dissocket->conn, argc, argv, NULL); if (!dissocket->reply) { radlog(L_ERR, "rlm_redis: (%s) REDIS error: %s", inst->xlat_name, dissocket->conn->errstr); dissocket = fr_connection_reconnect(inst->pool, dissocket); if (!dissocket) { error: *dissocket_p = NULL; return -1; } dissocket->reply = redisCommand(dissocket->conn, query); if (!dissocket->reply) { radlog(L_ERR, "rlm_redis (%s): failed after re-connect", inst->xlat_name); fr_connection_del(inst->pool, dissocket); goto error; } *dissocket_p = dissocket; } if (dissocket->reply->type == REDIS_REPLY_ERROR) { radlog(L_ERR, "rlm_redis (%s): query failed, %s", inst->xlat_name, query); return -1; } return 0; }
/* * Query the redis database */ int rlm_redis_query(REDISSOCK **dissocket_p, REDIS_INST *inst, char *query) { REDISSOCK *dissocket; if (!query || !*query || !inst || !dissocket_p) { return -1; } dissocket = *dissocket_p; DEBUG2("executing query %s", query); dissocket->reply = redisCommand(dissocket->conn, query); if (!dissocket->reply) { radlog(L_ERR, "rlm_redis: (%s) REDIS error: %s", inst->xlat_name, dissocket->conn->errstr); dissocket = fr_connection_reconnect(inst->pool, dissocket); if (!dissocket) { error: *dissocket_p = NULL; return -1; } dissocket->reply = redisCommand(dissocket->conn, query); if (!dissocket->reply) { radlog(L_ERR, "rlm_redis (%s): failed after re-connect", inst->xlat_name); fr_connection_del(inst->pool, dissocket); goto error; } *dissocket_p = dissocket; } if (dissocket->reply->type == REDIS_REPLY_ERROR) { radlog(L_ERR, "rlm_redis (%s): query failed, %s", inst->xlat_name, query); /* Free the reply just in case */ rlm_redis_finish_query(dissocket); return -1; } return 0; }