You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by ji...@apache.org on 2016/11/03 18:20:11 UTC
svn commit: r1767944 - in /apr/apr-util/branches/1.6.x: include/apr_redis.h
redis/apr_redis.c
Author: jim
Date: Thu Nov 3 18:20:11 2016
New Revision: 1767944
URL: http://svn.apache.org/viewvc?rev=1767944&view=rev
Log:
Some remaining stats fields
Modified:
apr/apr-util/branches/1.6.x/include/apr_redis.h
apr/apr-util/branches/1.6.x/redis/apr_redis.c
Modified: apr/apr-util/branches/1.6.x/include/apr_redis.h
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.6.x/include/apr_redis.h?rev=1767944&r1=1767943&r2=1767944&view=diff
==============================================================================
--- apr/apr-util/branches/1.6.x/include/apr_redis.h (original)
+++ apr/apr-util/branches/1.6.x/include/apr_redis.h Thu Nov 3 18:20:11 2016
@@ -367,7 +367,8 @@ APU_DECLARE(apr_status_t) apr_redis_mult
typedef enum
{
APR_RS_SERVER_MASTER, /**< Server is a master */
- APR_RS_SERVER_SLAVE /**< Server is a slave */
+ APR_RS_SERVER_SLAVE, /**< Server is a slave */
+ APR_RS_SERVER_UNKNOWN /**< Server role is unknown */
} apr_redis_server_role_t;
typedef struct
Modified: apr/apr-util/branches/1.6.x/redis/apr_redis.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.6.x/redis/apr_redis.c?rev=1767944&r1=1767943&r2=1767944&view=diff
==============================================================================
--- apr/apr-util/branches/1.6.x/redis/apr_redis.c (original)
+++ apr/apr-util/branches/1.6.x/redis/apr_redis.c Thu Nov 3 18:20:11 2016
@@ -1196,7 +1196,8 @@ apr_redis_version(apr_redis_server_t *rs
/* Have we already obtained the version number? */
if (rs->version.major != 0) {
- *baton = apr_pstrdup(p, rs->version.number);
+ if (baton)
+ *baton = apr_pstrdup(p, rs->version.number);
return APR_SUCCESS;
}
if (apr_pool_create(&subpool, p) != APR_SUCCESS) {
@@ -1213,15 +1214,18 @@ apr_redis_version(apr_redis_server_t *rs
}
ptr = strstr(*baton, RV_FIELD);
- rs->version.major = strtol(ptr + sizeof(RV_FIELD) - 1, &eptr, 10);
- ptr = eptr + 1;
- rs->version.minor = strtol(ptr, &eptr, 10);
- ptr = eptr + 1;
- rs->version.patch = strtol(ptr, &eptr, 10);
- rs->version.number = apr_psprintf(rs->p, "%d.%d.%d",
- rs->version.major, rs->version.minor,
- rs->version.patch);
- *baton = apr_pstrdup(p, rs->version.number);
+ if (ptr) {
+ rs->version.major = strtol(ptr + sizeof(RV_FIELD) - 1, &eptr, 10);
+ ptr = eptr + 1;
+ rs->version.minor = strtol(ptr, &eptr, 10);
+ ptr = eptr + 1;
+ rs->version.patch = strtol(ptr, &eptr, 10);
+ rs->version.number = apr_psprintf(rs->p, "%d.%d.%d",
+ rs->version.major, rs->version.minor,
+ rs->version.patch);
+ }
+ if (baton)
+ *baton = apr_pstrdup(p, rs->version.number);
if (subpool != p) {
apr_pool_destroy(subpool);
}
@@ -1460,6 +1464,7 @@ apr_redis_stats(apr_redis_server_t *rs,
char *info;
apr_pool_t *subpool;
apr_redis_stats_t *ret;
+ char *ptr;
if (apr_pool_create(&subpool, p) != APR_SUCCESS) {
/* well, we tried */
@@ -1474,7 +1479,38 @@ apr_redis_stats(apr_redis_server_t *rs,
return rv;
}
ret = apr_pcalloc(p, sizeof(apr_redis_stats_t));
+ /* Get the bulk of the stats */
update_stats(info, ret);
+
+ /* Now the version number */
+ if (rs->version.major != 0) {
+ ret->major = rs->version.major;
+ ret->minor = rs->version.minor;
+ ret->patch = rs->version.patch;
+ }
+ else {
+ char *eptr;
+ ptr = strstr(info, RV_FIELD);
+ if (ptr) {
+ ret->major = rs->version.major = strtol(ptr + sizeof(RV_FIELD) - 1, &eptr, 10);
+ ptr = eptr + 1;
+ ret->minor = rs->version.minor = strtol(ptr, &eptr, 10);
+ ptr = eptr + 1;
+ ret->patch = rs->version.patch = strtol(ptr, &eptr, 10);
+ }
+ }
+
+ /* Finally, the role */
+ ptr = strstr(info, "role:");
+ if (!ptr) {
+ ret->role = APR_RS_SERVER_UNKNOWN;
+ }
+ else if (!strncmp("master", ptr + sizeof("role:") - 1, sizeof("master")-1)) {
+ ret->role = APR_RS_SERVER_MASTER;
+ }
+ else {
+ ret->role = APR_RS_SERVER_SLAVE;
+ }
if (stats) {
*stats = ret;
}