@@ -5624,42 +5624,38 @@ int redis_xgroup_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
56245624int redis_xinfo_cmd (INTERNAL_FUNCTION_PARAMETERS , RedisSock * redis_sock ,
56255625 char * * cmd , int * cmd_len , short * slot , void * * ctx )
56265626{
5627- char * op , * key , * arg = NULL ;
5628- size_t oplen , keylen , arglen ;
5627+ zend_string * op = NULL , * key = NULL , * arg = NULL ;
5628+ smart_string cmdstr = { 0 } ;
56295629 zend_long count = -1 ;
5630- int argc = ZEND_NUM_ARGS ();
5631- char fmt [] = "skssl" ;
5632-
5633- if (argc > 4 || zend_parse_parameters (ZEND_NUM_ARGS (), "s|ssl" ,
5634- & op , & oplen , & key , & keylen , & arg ,
5635- & arglen , & count ) == FAILURE )
5636- {
5637- return FAILURE ;
5638- }
56395630
5640- /* Handle everything except XINFO STREAM */
5641- if ( strncasecmp ( op , "STREAM" , 6 ) != 0 ) {
5642- fmt [ argc ] = '\0' ;
5643- * cmd_len = REDIS_CMD_SPPRINTF ( cmd , "XINFO" , fmt , op , oplen , key , keylen ,
5644- arg , arglen );
5645- return SUCCESS ;
5646- }
5631+ ZEND_PARSE_PARAMETERS_START ( 1 , 4 )
5632+ Z_PARAM_STR ( op )
5633+ Z_PARAM_OPTIONAL
5634+ Z_PARAM_STR_OR_NULL ( key )
5635+ Z_PARAM_STR_OR_NULL ( arg )
5636+ Z_PARAM_LONG ( count )
5637+ ZEND_PARSE_PARAMETERS_END_EX ( return FAILURE );
56475638
5648- /* 'FULL' is the only legal option to XINFO STREAM */
5649- if (argc > 2 && strncasecmp (arg , "FULL" , 4 ) != 0 ) {
5650- php_error_docref (NULL , E_WARNING , "'%s' is not a valid option for XINFO STREAM" , arg );
5639+ if ((arg != NULL && key == NULL) || (count != -1 && (key == NULL || arg == NULL))) {
5640+ php_error_docref (NULL , E_WARNING , "Cannot pass a non-null optional argument after a NULL one." );
56515641 return FAILURE ;
56525642 }
56535643
5654- /* If we have a COUNT bump the argument count to account for the 'COUNT' literal */
5655- if ( argc == 4 ) argc ++ ;
5644+ REDIS_CMD_INIT_SSTR_STATIC ( & cmdstr , 1 + ( key != NULL ) + ( arg != NULL ) + ( count > -1 ? 2 : 0 ), "XINFO" );
5645+ redis_cmd_append_sstr_zstr ( & cmdstr , op ) ;
56565646
5657- fmt [argc ] = '\0' ;
5647+ if (key != NULL )
5648+ redis_cmd_append_sstr_key (& cmdstr , ZSTR_VAL (key ), ZSTR_LEN (key ), redis_sock , slot );
5649+ if (arg != NULL )
5650+ redis_cmd_append_sstr_zstr (& cmdstr , arg );
56585651
5659- /* Build our XINFO STREAM variant */
5660- * cmd_len = REDIS_CMD_SPPRINTF (cmd , "XINFO" , fmt , "STREAM" , 6 , key , keylen ,
5661- "FULL" , 4 , "COUNT" , 5 , count );
5652+ if (count > -1 ) {
5653+ REDIS_CMD_APPEND_SSTR_STATIC (& cmdstr , "COUNT" );
5654+ redis_cmd_append_sstr_long (& cmdstr , count );
5655+ }
56625656
5657+ * cmd = cmdstr .c ;
5658+ * cmd_len = cmdstr .len ;
56635659 return SUCCESS ;
56645660}
56655661
0 commit comments