Skip to content

Commit 97b7547

Browse files
Allow for NULL in Redis::multi()
This commit allows the caller to pass NULL specifically into Redis::multi, which will treat it as a non argument (defaulting to multi mode). In addition, if an argument is passed that is not Redis::MULTI OR Redis::PIPELINE, we now issue a warning. Addresses phpredis#525
1 parent c1f862c commit 97b7547

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

redis.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5230,9 +5230,12 @@ PHP_METHOD(Redis, multi)
52305230
char * response;
52315231
zval *object;
52325232
long multi_value = MULTI;
5233+
zend_bool is_null = 0;
52335234

5234-
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|l",
5235-
&object, redis_ce, &multi_value) == FAILURE) {
5235+
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|l!",
5236+
&object, redis_ce, &multi_value, &is_null)
5237+
== FAILURE)
5238+
{
52365239
RETURN_FALSE;
52375240
}
52385241

@@ -5242,11 +5245,19 @@ PHP_METHOD(Redis, multi)
52425245
RETURN_FALSE;
52435246
}
52445247

5245-
if(multi_value == MULTI || multi_value == PIPELINE) {
5246-
redis_sock->mode = multi_value;
5248+
/* Use our default (MULTI) if we were passed a NULL value, otherwise check
5249+
* it for MULTI or PIPELINE */
5250+
if (is_null) {
5251+
redis_sock->mode = MULTI;
5252+
} else if(multi_value == MULTI || multi_value == PIPELINE) {
5253+
redis_sock->mode = multi_value;
52475254
} else {
5255+
/* Invalid multi argument */
5256+
php_error_docref(NULL TSRMLS_CC, E_WARNING,
5257+
"Invalid mode (must be Redis::MULTI, or Redis::PIPELINE)");
5258+
52485259
RETURN_FALSE;
5249-
}
5260+
}
52505261

52515262
redis_sock->current = NULL;
52525263

0 commit comments

Comments
 (0)