@@ -2707,122 +2707,13 @@ PHP_METHOD(Redis, wait) {
27072707 REDIS_PROCESS_RESPONSE (redis_long_response );
27082708}
27092709
2710- /* Construct a PUBSUB command */
2711- PHP_REDIS_API int
2712- redis_build_pubsub_cmd (RedisSock * redis_sock , char * * ret , PUBSUB_TYPE type ,
2713- zval * arg )
2714- {
2715- HashTable * ht_chan ;
2716- zval * z_ele ;
2717- smart_string cmd = {0 };
2718-
2719- if (type == PUBSUB_CHANNELS ) {
2720- if (arg ) {
2721- /* With a pattern */
2722- return REDIS_SPPRINTF (ret , "PUBSUB" , "sk" , "CHANNELS" , sizeof ("CHANNELS" ) - 1 ,
2723- Z_STRVAL_P (arg ), Z_STRLEN_P (arg ));
2724- } else {
2725- /* No pattern */
2726- return REDIS_SPPRINTF (ret , "PUBSUB" , "s" , "CHANNELS" , sizeof ("CHANNELS" ) - 1 );
2727- }
2728- } else if (type == PUBSUB_NUMSUB ) {
2729- ht_chan = Z_ARRVAL_P (arg );
2730-
2731- // Add PUBSUB and NUMSUB bits
2732- redis_cmd_init_sstr (& cmd , zend_hash_num_elements (ht_chan )+ 1 , "PUBSUB" , sizeof ("PUBSUB" )- 1 );
2733- redis_cmd_append_sstr (& cmd , "NUMSUB" , sizeof ("NUMSUB" )- 1 );
2734-
2735- /* Iterate our elements */
2736- ZEND_HASH_FOREACH_VAL (ht_chan , z_ele ) {
2737- zend_string * zstr = zval_get_string (z_ele );
2738- redis_cmd_append_sstr_key (& cmd , ZSTR_VAL (zstr ), ZSTR_LEN (zstr ), redis_sock , NULL );
2739- zend_string_release (zstr );
2740- } ZEND_HASH_FOREACH_END ();
2741-
2742- /* Set return */
2743- * ret = cmd .c ;
2744- return cmd .len ;
2745- } else if (type == PUBSUB_NUMPAT ) {
2746- return REDIS_SPPRINTF (ret , "PUBSUB" , "s" , "NUMPAT" , sizeof ("NUMPAT" ) - 1 );
2747- }
2748-
2749- /* Shouldn't ever happen */
2750- return -1 ;
2751- }
2752-
27532710/*
27542711 * {{{ proto Redis::pubsub("channels", pattern);
27552712 * proto Redis::pubsub("numsub", Array channels);
27562713 * proto Redis::pubsub("numpat"); }}}
27572714 */
27582715PHP_METHOD (Redis , pubsub ) {
2759- zval * object ;
2760- RedisSock * redis_sock ;
2761- char * keyword , * cmd ;
2762- int cmd_len ;
2763- size_t kw_len ;
2764- PUBSUB_TYPE type ;
2765- zval * arg = NULL ;
2766-
2767- // Parse arguments
2768- if (zend_parse_method_parameters (ZEND_NUM_ARGS (), getThis (),
2769- "Os|z" , & object , redis_ce , & keyword ,
2770- & kw_len , & arg )== FAILURE )
2771- {
2772- RETURN_FALSE ;
2773- }
2774-
2775- /* Validate our sub command keyword, and that we've got proper arguments */
2776- if (!strncasecmp (keyword , "channels" , sizeof ("channels" ))) {
2777- /* One (optional) string argument */
2778- if (arg && Z_TYPE_P (arg ) != IS_STRING ) {
2779- RETURN_FALSE ;
2780- }
2781- type = PUBSUB_CHANNELS ;
2782- } else if (!strncasecmp (keyword , "numsub" , sizeof ("numsub" ))) {
2783- /* One array argument */
2784- if (ZEND_NUM_ARGS () < 2 || Z_TYPE_P (arg ) != IS_ARRAY ||
2785- zend_hash_num_elements (Z_ARRVAL_P (arg )) == 0 )
2786- {
2787- RETURN_FALSE ;
2788- }
2789- type = PUBSUB_NUMSUB ;
2790- } else if (!strncasecmp (keyword , "numpat" , sizeof ("numpat" ))) {
2791- type = PUBSUB_NUMPAT ;
2792- } else {
2793- /* Invalid keyword */
2794- RETURN_FALSE ;
2795- }
2796-
2797- /* Grab our socket context object */
2798- if ((redis_sock = redis_sock_get (object , 0 )) == NULL ) {
2799- RETURN_FALSE ;
2800- }
2801-
2802- /* Construct our "PUBSUB" command */
2803- cmd_len = redis_build_pubsub_cmd (redis_sock , & cmd , type , arg );
2804-
2805- REDIS_PROCESS_REQUEST (redis_sock , cmd , cmd_len );
2806-
2807- if (type == PUBSUB_NUMSUB ) {
2808- if (IS_ATOMIC (redis_sock )) {
2809- if (redis_mbulk_reply_zipped_keys_int (INTERNAL_FUNCTION_PARAM_PASSTHRU ,
2810- redis_sock , NULL , NULL ) < 0 )
2811- {
2812- RETURN_FALSE ;
2813- }
2814- }
2815- REDIS_PROCESS_RESPONSE (redis_mbulk_reply_zipped_keys_int );
2816- } else {
2817- if (IS_ATOMIC (redis_sock )) {
2818- if (redis_read_variant_reply (INTERNAL_FUNCTION_PARAM_PASSTHRU ,
2819- redis_sock , NULL , NULL ) < 0 )
2820- {
2821- RETURN_FALSE ;
2822- }
2823- }
2824- REDIS_PROCESS_RESPONSE (redis_read_variant_reply );
2825- }
2716+ REDIS_PROCESS_CMD (pubsub , redis_pubsub_response );
28262717}
28272718
28282719/* {{{ proto variant Redis::eval(string script, [array keys, long num_keys]) */
0 commit comments