Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for redis command 'ping' #119

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/nc_message.h
Expand Up @@ -57,6 +57,7 @@ typedef enum msg_type {
MSG_RSP_MC_ERROR, /* memcache error responses */
MSG_RSP_MC_CLIENT_ERROR,
MSG_RSP_MC_SERVER_ERROR,
MSG_REQ_REDIS_PING, /* redis command ping */
MSG_REQ_REDIS_DEL, /* redis commands - keys */
MSG_REQ_REDIS_EXISTS,
MSG_REQ_REDIS_EXPIRE,
Expand Down
11 changes: 11 additions & 0 deletions src/nc_request.c
Expand Up @@ -475,6 +475,17 @@ req_filter(struct context *ctx, struct conn *conn, struct msg *msg)
return true;
}

/*
* Hanlde "PING\r\n"
*
*/
if (msg->type == MSG_REQ_REDIS_PING) {
log_debug(LOG_INFO, "filter ping req %"PRIu64" from c %d", msg->id,
conn->sd);
reply(ctx, conn, msg, "+PONG\r\n");
return true;
}

return false;
}

Expand Down
36 changes: 25 additions & 11 deletions src/proto/nc_redis.c
Expand Up @@ -28,6 +28,7 @@
static bool
redis_arg0(struct msg *r)
{

switch (r->type) {
case MSG_REQ_REDIS_EXISTS:
case MSG_REQ_REDIS_PERSIST:
Expand Down Expand Up @@ -57,6 +58,8 @@ redis_arg0(struct msg *r)

case MSG_REQ_REDIS_ZCARD:
case MSG_REQ_REDIS_AUTH:

case MSG_REQ_REDIS_PING:
return true;

default:
Expand Down Expand Up @@ -101,6 +104,7 @@ redis_arg1(struct msg *r)
case MSG_REQ_REDIS_ZRANK:
case MSG_REQ_REDIS_ZREVRANK:
case MSG_REQ_REDIS_ZSCORE:
case MSG_REQ_REDIS_PING:
return true;

default:
Expand Down Expand Up @@ -562,6 +566,11 @@ redis_parse_req(struct msg *r)
break;
}

if (str4icmp(m, 'p', 'i', 'n', 'g')) {
r->type = MSG_REQ_REDIS_PING;
break;
}

break;

case 5:
Expand Down Expand Up @@ -936,17 +945,22 @@ redis_parse_req(struct msg *r)
break;

case SW_REQ_TYPE_LF:
switch (ch) {
case LF:
if (redis_argeval(r)) {
state = SW_ARG1_LEN;
} else {
state = SW_KEY_LEN;
}
break;
if (r->type == MSG_REQ_REDIS_PING) {
goto done;
}
else {
switch (ch) {
case LF:
if (redis_argeval(r)) {
state = SW_ARG1_LEN;
} else {
state = SW_KEY_LEN;
}
break;

default:
goto error;
default:
goto error;
}
}

break;
Expand Down Expand Up @@ -1488,7 +1502,7 @@ redis_parse_req(struct msg *r)
return;

done:
ASSERT(r->type > MSG_UNKNOWN && r->type < MSG_SENTINEL);
ASSERT(r->type == MSG_REQ_REDIS_PING || (r->type > MSG_UNKNOWN && r->type < MSG_SENTINEL) );
r->pos = p + 1;
ASSERT(r->pos <= b->last);
r->state = SW_START;
Expand Down