Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
Avoid socket connection in destructor
Replace IF_ATOMIC/IF_MULTI/IF_PIPELINE macroses with
IS_ATOMIC/IS_MULTI/IS_PIPELINE respectively.
Remove IF_NOT_* macroses
  • Loading branch information
yatsukhnenko committed Nov 17, 2017
1 parent 479420f commit 7c5a68c
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 136 deletions.
17 changes: 7 additions & 10 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -507,12 +507,9 @@ typedef enum _PUBSUB_TYPE {
#define MULTI 1
#define PIPELINE 2

#define IF_ATOMIC() if (redis_sock->mode == ATOMIC)
#define IF_NOT_ATOMIC() if (redis_sock->mode != ATOMIC)
#define IF_MULTI() if (redis_sock->mode & MULTI)
#define IF_NOT_MULTI() if (!(redis_sock->mode & MULTI))
#define IF_PIPELINE() if (redis_sock->mode & PIPELINE)
#define IF_NOT_PIPELINE() if (!(redis_sock->mode & PIPELINE))
#define IS_ATOMIC(redis_sock) (redis_sock->mode == ATOMIC)
#define IS_MULTI(redis_sock) (redis_sock->mode & MULTI)
#define IS_PIPELINE(redis_sock) (redis_sock->mode & PIPELINE)

#define PIPELINE_ENQUEUE_COMMAND(cmd, cmd_len) do { \
if (redis_sock->pipeline_cmd == NULL) { \
Expand Down Expand Up @@ -547,15 +544,15 @@ typedef enum _PUBSUB_TYPE {
} while (0)

#define REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len) \
IF_PIPELINE() { \
if (IS_PIPELINE(redis_sock)) { \
PIPELINE_ENQUEUE_COMMAND(cmd, cmd_len); \
} else { \
SOCKET_WRITE_COMMAND(redis_sock, cmd, cmd_len); \
} \
efree(cmd);

#define REDIS_PROCESS_RESPONSE_CLOSURE(function, closure_context) \
IF_NOT_PIPELINE() { \
if (!IS_PIPELINE(redis_sock)) { \
if (redis_response_enqueued(redis_sock TSRMLS_CC) != SUCCESS) { \
RETURN_FALSE; \
} \
Expand Down Expand Up @@ -583,7 +580,7 @@ typedef enum _PUBSUB_TYPE {
RETURN_FALSE; \
} \
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len); \
IF_ATOMIC() { \
if (IS_ATOMIC(redis_sock)) { \
resp_func(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, ctx); \
} else { \
REDIS_PROCESS_RESPONSE_CLOSURE(resp_func, ctx) \
Expand All @@ -599,7 +596,7 @@ typedef enum _PUBSUB_TYPE {
RETURN_FALSE; \
} \
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len); \
IF_ATOMIC() { \
if (IS_ATOMIC(redis_sock)) { \
resp_func(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, ctx); \
} else { \
REDIS_PROCESS_RESPONSE_CLOSURE(resp_func, ctx) \
Expand Down
Loading

0 comments on commit 7c5a68c

Please sign in to comment.