Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpredis/phpredis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavlo Yatsukhnenko <yatsukhnenko@gmail.com>2017-02-20 23:51:16 +0300
committerPavlo Yatsukhnenko <yatsukhnenko@gmail.com>2017-08-08 23:17:49 +0300
commit5874b0775b338a4e57c0f850fd3e25a19735fd6a (patch)
tree18e0e1308beb9dc7ec57a7f543d32ca6d0788b89 /common.h
parenta56ed7f9f943394069019afa8a429e7aa04246b2 (diff)
Allow mixing multi and pipeline modes
Diffstat (limited to 'common.h')
-rw-r--r--common.h32
1 files changed, 19 insertions, 13 deletions
diff --git a/common.h b/common.h
index ed47b92d..4322dedd 100644
--- a/common.h
+++ b/common.h
@@ -468,12 +468,17 @@ typedef enum _PUBSUB_TYPE {
#define BITOP_MIN_OFFSET 0
#define BITOP_MAX_OFFSET 4294967295U
+/* Transaction modes */
+#define ATOMIC 0
+#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 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 PIPELINE_ENQUEUE_COMMAND(cmd, cmd_len) do { \
if (redis_sock->pipeline_cmd == NULL) { \
@@ -494,14 +499,14 @@ typedef enum _PUBSUB_TYPE {
}
#define REDIS_SAVE_CALLBACK(callback, closure_context) do { \
- fold_item *f1 = malloc(sizeof(fold_item)); \
- f1->fun = (void *)callback; \
- f1->ctx = closure_context; \
- f1->next = NULL; \
+ fold_item *fi = malloc(sizeof(fold_item)); \
+ fi->fun = (void *)callback; \
+ fi->ctx = closure_context; \
+ fi->next = NULL; \
if (redis_sock->current) { \
- redis_sock->current->next = f1; \
+ redis_sock->current->next = fi; \
} \
- redis_sock->current = f1; \
+ redis_sock->current = fi; \
if (NULL == redis_sock->head) { \
redis_sock->head = redis_sock->current; \
} \
@@ -516,7 +521,7 @@ typedef enum _PUBSUB_TYPE {
efree(cmd);
#define REDIS_PROCESS_RESPONSE_CLOSURE(function, closure_context) \
- IF_MULTI() { \
+ IF_NOT_PIPELINE() { \
if (redis_response_enqueued(redis_sock TSRMLS_CC) != SUCCESS) { \
RETURN_FALSE; \
} \
@@ -592,7 +597,8 @@ typedef enum _PUBSUB_TYPE {
#define IS_LEX_ARG(s,l) \
(l>0 && (*s=='(' || *s=='[' || (l==1 && (*s=='+' || *s=='-'))))
-typedef enum {ATOMIC, MULTI, PIPELINE} redis_mode;
+#define REDIS_ENABLE_MODE(redis_sock, m) (redis_sock->mode |= m)
+#define REDIS_DISABLE_MODE(redis_sock, m) (redis_sock->mode &= ~m)
typedef struct fold_item {
zval * (*fun)(INTERNAL_FUNCTION_PARAMETERS, void *, ...);
@@ -621,7 +627,7 @@ typedef struct {
char *prefix;
int prefix_len;
- redis_mode mode;
+ short mode;
fold_item *head;
fold_item *current;