Skip to content

Commit f6de217

Browse files
committed
MULTI/EXEC and pipeline working for the first time.
1 parent c731c80 commit f6de217

File tree

3 files changed

+21
-25
lines changed

3 files changed

+21
-25
lines changed

common.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@
7777
}\
7878
}
7979

80-
#define REDIS_ELSE_IF_MULTI() \
80+
#define REDIS_ELSE_IF_MULTI(function) \
8181
else if(get_flag(object) == REDIS_MULTI) { \
8282
if(redis_response_enqueued(redis_sock TSRMLS_CC) == 1) {\
83+
REDIS_MULTI_RESPONSE(function); \
8384
RETURN_ZVAL(getThis(), 1, 0);\
8485
} else {\
8586
RETURN_FALSE;\
@@ -103,7 +104,7 @@ else if(get_flag(object) == REDIS_MULTI) { \
103104
}
104105

105106
#define REDIS_PROCESS_RESPONSE(function) \
106-
REDIS_ELSE_IF_MULTI() \
107+
REDIS_ELSE_IF_MULTI(function) \
107108
REDIS_ELSE_IF_PIPELINE(function);
108109

109110
/* {{{ struct RedisSock */

redis.c

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3154,23 +3154,18 @@ PHP_METHOD(Redis, hIncrBy)
31543154

31553155
PHPAPI int redis_response_enqueued(RedisSock *redis_sock TSRMLS_DC) {
31563156

3157-
char *response, *ret;
3158-
int response_len;
3157+
char *response;
3158+
int response_len, ret = 0;
31593159

31603160
if ((response = redis_sock_read(redis_sock, &response_len TSRMLS_CC)) == NULL) {
31613161
return 0;
31623162
}
31633163

3164-
if(response[0] == '+') {
3165-
if(strncmp(response, "QUEUED", 6 )) {
3166-
return 1;
3167-
} else {
3168-
return 1;
3169-
}
3170-
} else {
3171-
efree(response);
3172-
return 0;
3173-
}
3164+
if(strncmp(response, "+QUEUED", 7) == 0) {
3165+
ret = 1;
3166+
}
3167+
efree(response);
3168+
return ret;
31743169
}
31753170

31763171
/* flag : get, set {REDIS_ATOMIC, REDIS_MULTI, REDIS_PIPELINE} */
@@ -3199,7 +3194,7 @@ PHP_METHOD(Redis, multi)
31993194
if(multi_value == REDIS_MULTI || multi_value == REDIS_PIPELINE) {
32003195
set_flag(object, multi_value);
32013196
} else {
3202-
php_printf("error[%f] !! \n", multi_value);
3197+
/* php_printf("error[%f] !! \n", multi_value); */
32033198
exit(-1);
32043199
}
32053200

@@ -3223,18 +3218,14 @@ PHP_METHOD(Redis, multi)
32233218
RETURN_FALSE;
32243219
}
32253220

3226-
if(response_len == 3 & response[0] == '+' && response[1] == 'O' && response[2] == 'K') {
3221+
if(strncmp(response, "+OK", 3) == 0) {
3222+
efree(response);
32273223
RETURN_ZVAL(getThis(), 1, 0);
32283224
}
3225+
efree(response);
32293226
RETURN_FALSE;
32303227
}
32313228
IF_PIPELINE() {
3232-
/*
3233-
head_request = malloc(sizeof(request_item));
3234-
current_request = head_request;
3235-
current_request->function_name = strdup("__begin__");
3236-
current_request->request_str = NULL;
3237-
*/
32383229
head_request = current_request = NULL;
32393230
RETURN_ZVAL(getThis(), 1, 0);
32403231
}
@@ -3365,8 +3356,6 @@ PHP_METHOD(Redis, exec)
33653356

33663357
IF_MULTI() {
33673358

3368-
current = NULL;
3369-
head = NULL;
33703359
cmd_len = redis_cmd_format(&cmd, "EXEC \r\n");
33713360

33723361
if (redis_sock_write(redis_sock, cmd, cmd_len) < 0) {
@@ -3376,8 +3365,12 @@ PHP_METHOD(Redis, exec)
33763365
efree(cmd);
33773366

33783367
if (redis_sock_read_multibulk_multi_reply(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock TSRMLS_CC) < 0) {
3368+
current = NULL;
3369+
head = NULL;
33793370
RETURN_FALSE;
33803371
}
3372+
current = NULL;
3373+
head = NULL;
33813374
set_flag(object, REDIS_ATOMIC);
33823375
}
33833376

@@ -3425,6 +3418,7 @@ PHPAPI int redis_sock_read_multibulk_multi_reply_loop(INTERNAL_FUNCTION_PARAMETE
34253418
RedisSock *redis_sock, zval *z_tab, int numElems TSRMLS_DC)
34263419
{
34273420

3421+
/*
34283422
zval *z_response;
34293423
current = head;
34303424
if(numElems == 0) {
@@ -3433,6 +3427,7 @@ PHPAPI int redis_sock_read_multibulk_multi_reply_loop(INTERNAL_FUNCTION_PARAMETE
34333427
current = current->next;
34343428
}
34353429
}
3430+
*/
34363431

34373432
for(current = head; current; current = current->next) {
34383433
fold_this_item(INTERNAL_FUNCTION_PARAM_PASSTHRU, current, redis_sock, z_tab TSRMLS_DC);

tests/testPipeline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ function test1($r, $type) {
162162

163163
}
164164

165-
// test1($r, Redis::MULTI);
165+
test1($r, Redis::MULTI);
166166
test1($r, Redis::PIPELINE);
167167

168168

0 commit comments

Comments
 (0)