3232
3333#include <zend_exceptions.h>
3434
35- /* Config operations */
36- typedef enum redisConfigOp {
37- REDIS_CFG_RESETSTAT ,
38- REDIS_CFG_REWRITE ,
39- REDIS_CFG_GET ,
40- REDIS_CFG_SET ,
41- } redisConfigOp ;
42-
4335/* Georadius sort type */
4436typedef enum geoSortType {
4537 SORT_NONE ,
@@ -736,21 +728,6 @@ int redis_zrangebyscore_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
736728 return SUCCESS ;
737729}
738730
739- static int redis_get_config_op (enum redisConfigOp * dst , zend_string * op ) {
740- if (zend_string_equals_literal_ci (op , "RESETSTAT" ))
741- * dst = REDIS_CFG_RESETSTAT ;
742- else if (zend_string_equals_literal_ci (op , "REWRITE" ))
743- * dst = REDIS_CFG_REWRITE ;
744- else if (zend_string_equals_literal_ci (op , "GET" ))
745- * dst = REDIS_CFG_GET ;
746- else if (zend_string_equals_literal_ci (op , "SET" ))
747- * dst = REDIS_CFG_SET ;
748- else
749- return FAILURE ;
750-
751- return SUCCESS ;
752- }
753-
754731static int redis_build_config_get_cmd (smart_string * dst , zval * val ) {
755732 zend_string * zstr ;
756733 int ncfg ;
@@ -839,7 +816,6 @@ redis_config_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
839816{
840817 zend_string * op = NULL , * arg = NULL ;
841818 smart_string cmdstr = {0 };
842- enum redisConfigOp cfg_op ;
843819 int res = FAILURE ;
844820 zval * key = NULL ;
845821
@@ -850,29 +826,24 @@ redis_config_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
850826 Z_PARAM_STR_OR_NULL (arg )
851827 ZEND_PARSE_PARAMETERS_END_EX (return FAILURE );
852828
853- if (redis_get_config_op (& cfg_op , op ) != SUCCESS ) {
829+ if (zend_string_equals_literal_ci (op , "RESETSTAT ") ||
830+ zend_string_equals_literal_ci (op , "REWRITE "))
831+ {
832+ REDIS_CMD_INIT_SSTR_STATIC (& cmdstr , 1 , "CONFIG" );
833+ redis_cmd_append_sstr_zstr (& cmdstr , op );
834+ * ctx = redis_boolean_response ;
835+ res = SUCCESS ;
836+ } else if (zend_string_equals_literal_ci (op , "GET ")) {
837+ res = redis_build_config_get_cmd (& cmdstr , key );
838+ * ctx = redis_mbulk_reply_zipped_raw ;
839+ } else if (zend_string_equals_literal_ci (op , "SET ")) {
840+ res = redis_build_config_set_cmd (& cmdstr , key , arg );
841+ * ctx = redis_boolean_response ;
842+ } else {
854843 php_error_docref (NULL , E_WARNING , "Unknown operation '%s'" , ZSTR_VAL (op ));
855844 return FAILURE ;
856845 }
857846
858- switch (cfg_op ) {
859- case REDIS_CFG_RESETSTAT : /* fallthrough */
860- case REDIS_CFG_REWRITE :
861- REDIS_CMD_INIT_SSTR_STATIC (& cmdstr , 1 , "CONFIG" );
862- redis_cmd_append_sstr_zstr (& cmdstr , op );
863- * ctx = redis_boolean_response ;
864- res = SUCCESS ;
865- break ;
866- case REDIS_CFG_GET :
867- res = redis_build_config_get_cmd (& cmdstr , key );
868- * ctx = redis_mbulk_reply_zipped_raw ;
869- break ;
870- case REDIS_CFG_SET :
871- res = redis_build_config_set_cmd (& cmdstr , key , arg );
872- * ctx = redis_boolean_response ;
873- break ;
874- }
875-
876847 * cmd = cmdstr .c ;
877848 * cmd_len = cmdstr .len ;
878849 return res ;
0 commit comments