Skip to content

Commit

Permalink
use constant for redis reply
Browse files Browse the repository at this point in the history
  • Loading branch information
idning committed Nov 24, 2014
1 parent bf7b239 commit ed7c9b9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/proto/nc_redis.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
#include <nc_core.h>
#include <nc_proto.h>

#define AUTH_OK "+OK\r\n"
#define REPL_OK "+OK\r\n"
#define REPL_PONG "+PONG\r\n"

#define AUTH_INVALID_PASSWORD "-ERR invalid password\r\n"
#define AUTH_REQUIRE_PASSWORD "-NOAUTH Authentication required\r\n"
#define AUTH_NO_PASSWORD "-ERR Client sent AUTH, but no password is set\r\n"
Expand Down Expand Up @@ -2480,7 +2482,7 @@ redis_reply(struct msg *r)

switch (r->type) {
case MSG_REQ_REDIS_PING:
return msg_append(response, (uint8_t *)"+PONG\r\n", 7);
return msg_append(response, (uint8_t *)REPL_PONG, nc_strlen(REPL_PONG));

default:
NOT_REACHED();
Expand All @@ -2494,7 +2496,7 @@ redis_post_coalesce_mset(struct msg *request)
struct msg *response = request->peer;
rstatus_t status;

status = msg_append(response, (uint8_t *)"+OK\r\n", 5);
status = msg_append(response, (uint8_t *)REPL_OK, nc_strlen(REPL_OK));
if (status != NC_OK) {
response->error = 1; /* mark this msg as err */
response->err = errno;
Expand Down Expand Up @@ -2617,7 +2619,7 @@ redis_handle_auth_req(struct msg *request, struct msg *response)

if (redis_valid_auth(conn, request)) {
conn->need_auth = 0;
return msg_append(response, (uint8_t *)AUTH_OK, nc_strlen(AUTH_OK));
return msg_append(response, (uint8_t *)REPL_OK, nc_strlen(REPL_OK));
} else {
conn->need_auth = 1;
return msg_append(response, (uint8_t *)AUTH_INVALID_PASSWORD, nc_strlen(AUTH_INVALID_PASSWORD));
Expand Down

0 comments on commit ed7c9b9

Please sign in to comment.