@@ -5817,52 +5817,72 @@ int redis_xclaim_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
58175817}
58185818
58195819/* XGROUP HELP
5820- * XGROUP CREATE key groupname id [MKSTREAM]
5821- * XGROUP SETID key group id
5822- * XGROUP DESTROY key groupname
5823- * XGROUP DELCONSUMER key groupname consumername */
5820+ * XGROUP CREATE key group id [MKSTREAM] [ENTRIESREAD <n>]
5821+ * XGROUP SETID key group id [ENTRIESREAD <n>]
5822+ * XGROUP CREATECONSUMER key group consumer
5823+ * XGROUP DELCONSUMER key group consumer
5824+ * XGROUP DESTROY key group
5825+ */
58245826int redis_xgroup_cmd (INTERNAL_FUNCTION_PARAMETERS , RedisSock * redis_sock ,
58255827 char * * cmd , int * cmd_len , short * slot , void * * ctx )
58265828{
5827- char * op , * key = NULL , * arg1 = NULL , * arg2 = NULL ;
5828- size_t oplen , keylen , arg1len , arg2len ;
5829+ zend_string * op = NULL , * key = NULL , * group = NULL , * id_or_consumer = NULL ;
5830+ int nargs , is_create = 0 , is_setid = 0 ;
5831+ zend_long entries_read = -2 ;
5832+ smart_string cmdstr = {0 };
58295833 zend_bool mkstream = 0 ;
5830- int argc = ZEND_NUM_ARGS ();
58315834
5832- if (zend_parse_parameters (ZEND_NUM_ARGS (), "s|sssb" , & op , & oplen ,
5833- & key , & keylen , & arg1 , & arg1len , & arg2 , & arg2len ,
5834- & mkstream ) == FAILURE )
5835+ ZEND_PARSE_PARAMETERS_START (1 , 6 )
5836+ Z_PARAM_STR (op )
5837+ Z_PARAM_OPTIONAL
5838+ Z_PARAM_STR (key )
5839+ Z_PARAM_STR (group )
5840+ Z_PARAM_STR (id_or_consumer )
5841+ Z_PARAM_BOOL (mkstream )
5842+ Z_PARAM_LONG (entries_read )
5843+ ZEND_PARSE_PARAMETERS_END_EX (return FAILURE );
5844+
5845+ if (zend_string_equals_literal_ci (op , "HELP ")) {
5846+ nargs = 0 ;
5847+ } else if ((is_create = zend_string_equals_literal_ci (op , "CREATE" )) ||
5848+ (is_setid = zend_string_equals_literal_ci (op , "SETID" )) ||
5849+ zend_string_equals_literal_ci (op , "CREATECONSUMER" ) ||
5850+ zend_string_equals_literal_ci (op , "DELCONSUMER" ))
58355851 {
5852+ nargs = 3 ;
5853+ } else if (zend_string_equals_literal_ci (op , "DESTROY ")) {
5854+ nargs = 2 ;
5855+ } else {
5856+ php_error_docref (NULL , E_WARNING , "Unknown XGROUP operation '%s'" , ZSTR_VAL (op ));
58365857 return FAILURE ;
58375858 }
58385859
5839- if (argc == 1 && oplen == 4 && !strncasecmp (op , "HELP" , 4 )) {
5840- * cmd_len = REDIS_CMD_SPPRINTF (cmd , "XGROUP" , "s" , "HELP" , 4 );
5841- return SUCCESS ;
5842- } else if (argc >= 4 && (oplen == 6 && !strncasecmp (op , "CREATE" , 6 ))) {
5843- if (mkstream ) {
5844- * cmd_len = REDIS_CMD_SPPRINTF (cmd , "XGROUP" , "sksss" , op , oplen , key , keylen ,
5845- arg1 , arg1len , arg2 , arg2len , "MKSTREAM" ,
5846- sizeof ("MKSTREAM" ) - 1 );
5847- } else {
5848- * cmd_len = REDIS_CMD_SPPRINTF (cmd , "XGROUP" , "skss" , op , oplen , key , keylen ,
5849- arg1 , arg1len , arg2 , arg2len );
5850- }
5851- return SUCCESS ;
5852- } else if (argc == 4 && ((oplen == 5 && !strncasecmp (op , "SETID" , 5 )) ||
5853- (oplen == 11 && !strncasecmp (op , "DELCONSUMER" , 11 ))))
5854- {
5855- * cmd_len = REDIS_CMD_SPPRINTF (cmd , "XGROUP" , "skss" , op , oplen , key , keylen ,
5856- arg1 , arg1len , arg2 , arg2len );
5857- return SUCCESS ;
5858- } else if (argc == 3 && ((oplen == 7 && !strncasecmp (op , "DESTROY" , 7 )))) {
5859- * cmd_len = REDIS_CMD_SPPRINTF (cmd , "XGROUP" , "sks" , op , oplen , key ,
5860- keylen , arg1 , arg1len );
5861- return SUCCESS ;
5860+ if (ZEND_NUM_ARGS () < nargs ) {
5861+ php_error_docref (NULL , E_WARNING , "Operation '%s' requires %d arguments" , ZSTR_VAL (op ), nargs );
5862+ return FAILURE ;
58625863 }
58635864
5864- /* Didn't detect any valid XGROUP command pattern */
5865- return FAILURE ;
5865+ mkstream &= is_create ;
5866+ if (!(is_create || is_setid ))
5867+ entries_read = -2 ;
5868+
5869+ REDIS_CMD_INIT_SSTR_STATIC (& cmdstr , 1 + nargs + !!mkstream + (entries_read != -2 ? 2 : 0 ), "XGROUP" );
5870+ redis_cmd_append_sstr_zstr (& cmdstr , op );
5871+
5872+ if (nargs -- > 0 ) redis_cmd_append_sstr_key_zstr (& cmdstr , key , redis_sock , slot );
5873+ if (nargs -- > 0 ) redis_cmd_append_sstr_zstr (& cmdstr , group );
5874+ if (nargs -- > 0 ) redis_cmd_append_sstr_zstr (& cmdstr , id_or_consumer );
5875+
5876+ REDIS_CMD_APPEND_SSTR_OPT_STATIC (& cmdstr , !!mkstream , "MKSTREAM" );
5877+ if (entries_read != -2 ) {
5878+ REDIS_CMD_APPEND_SSTR_STATIC (& cmdstr , "ENTRIESREAD" );
5879+ redis_cmd_append_sstr_long (& cmdstr , entries_read );
5880+ }
5881+
5882+ * cmd = cmdstr .c ;
5883+ * cmd_len = cmdstr .len ;
5884+
5885+ return SUCCESS ;
58665886}
58675887
58685888/* XINFO CONSUMERS key group
0 commit comments