diff options
author | michael-grunder <michael.grunder@gmail.com> | 2019-06-03 21:46:03 +0300 |
---|---|---|
committer | Michael Grunder <michael.grunder@gmail.com> | 2019-06-04 23:37:52 +0300 |
commit | 0c17bd27a03f499f96fad90fb2fec069c3408156 (patch) | |
tree | 74bfcf63ba70b67118dfd41ca0e0f4feab0dc4d4 /redis_commands.c | |
parent | 6e4941706835d32bfce6b2843f791ef9720b7b88 (diff) |
Make the XREADGROUP optional COUNT and BLOCK arguments nullable.
Change the way we accept COUNT and BLOCK such that a user can pass NULL
to mean "no value". This is technically a breaking change, since
previously the value `-1` was used for "no value".
Fixes #1560
Diffstat (limited to 'redis_commands.c')
-rw-r--r-- | redis_commands.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/redis_commands.c b/redis_commands.c index b74092ed..006d3dc1 100644 --- a/redis_commands.c +++ b/redis_commands.c @@ -3466,15 +3466,22 @@ int redis_xreadgroup_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, char *group, *consumer; size_t grouplen, consumerlen; int scount, argc; - zend_long count = -1, block = -1; + zend_long count, block; + zend_bool no_count = 1, no_block = 1; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssa|ll", &group, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssa|l!l!", &group, &grouplen, &consumer, &consumerlen, &z_streams, - &count, &block) == FAILURE) + &count, &no_count, &block, &no_block) == FAILURE) { return FAILURE; } + /* Negative COUNT or BLOCK is illegal so abort immediately */ + if ((!no_count && count < 0) || (!no_block && block < 0)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Negative values for COUNT or BLOCK are illegal."); + return FAILURE; + } + /* Redis requires at least one stream */ kt = Z_ARRVAL_P(z_streams); if ((scount = zend_hash_num_elements(kt)) < 1) { @@ -3482,7 +3489,7 @@ int redis_xreadgroup_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, } /* Calculate argc and start constructing commands */ - argc = 4 + (2 * scount) + (2 * (count > -1)) + (2 * (block > -1)); + argc = 4 + (2 * scount) + (2 * !no_count) + (2 * !no_block); REDIS_CMD_INIT_SSTR_STATIC(&cmdstr, argc, "XREADGROUP"); /* Group and consumer */ @@ -3491,13 +3498,13 @@ int redis_xreadgroup_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, redis_cmd_append_sstr(&cmdstr, consumer, consumerlen); /* Append COUNT if we have it */ - if (count > -1) { + if (!no_count) { REDIS_CMD_APPEND_SSTR_STATIC(&cmdstr, "COUNT"); redis_cmd_append_sstr_long(&cmdstr, count); } /* Append BLOCK argument if we have it */ - if (block > -1) { + if (!no_block) { REDIS_CMD_APPEND_SSTR_STATIC(&cmdstr, "BLOCK"); redis_cmd_append_sstr_long(&cmdstr, block); } |