@@ -273,6 +273,9 @@ static void redis_response_format_array_item(String *buf, zval *item) {
273273 redis_response_format (buf, Redis::REPLY_MAP, item);
274274 }
275275 break ;
276+ case IS_NULL:
277+ redis_response_format (buf, Redis::REPLY_NIL, item);
278+ break ;
276279 default :
277280 redis_response_format (buf, Redis::REPLY_STRING, item);
278281 break ;
@@ -299,23 +302,29 @@ static bool redis_response_format(String *buf, zend_long type, zval *value) {
299302 } else if (type == Redis::REPLY_STRING) {
300303 if (!value) {
301304 _no_value:
302- php_swoole_fatal_error (E_WARNING , " require more parameters" );
305+ zend_throw_exception (swoole_exception_ce , " require more parameters" , SW_ERROR_INVALID_PARAMS );
303306 return false ;
304307 }
305308 zend::String str_value (value);
306- if (str_value.len () > SW_REDIS_MAX_STRING_SIZE || str_value.len () < 1 ) {
307- php_swoole_fatal_error (E_WARNING, " invalid string size" );
309+ if (sw_unlikely (str_value.len () > SW_REDIS_MAX_STRING_SIZE)) {
310+ zend_throw_exception (swoole_exception_ce,
311+ " the length of given string exceeds the maximum allowed value" ,
312+ SW_ERROR_INVALID_PARAMS);
308313 return false ;
314+ } else if (sw_unlikely (str_value.len () == 0 )) {
315+ buf->append (" $0\r\n\r\n " );
316+ } else {
317+ SW_STRING_FORMAT (buf, " $%zu\r\n " , str_value.len ());
318+ buf->append (str_value.val (), str_value.len ());
319+ buf->append (SW_CRLF, SW_CRLF_LEN);
309320 }
310- SW_STRING_FORMAT (buf, " $%zu\r\n " , str_value.len ());
311- buf->append (str_value.val (), str_value.len ());
312- buf->append (SW_CRLF, SW_CRLF_LEN);
313321 } else if (type == Redis::REPLY_SET) {
314322 if (!value) {
315323 goto _no_value;
316324 }
317325 if (!ZVAL_IS_ARRAY (value)) {
318- php_swoole_fatal_error (E_WARNING, " the second parameter should be an array" );
326+ zend_throw_exception (
327+ swoole_exception_ce, " the second parameter should be an array" , SW_ERROR_INVALID_PARAMS);
319328 }
320329 SW_STRING_FORMAT (buf, " *%d\r\n " , zend_hash_num_elements (Z_ARRVAL_P (value)));
321330
@@ -329,7 +338,8 @@ static bool redis_response_format(String *buf, zend_long type, zval *value) {
329338 goto _no_value;
330339 }
331340 if (!ZVAL_IS_ARRAY (value)) {
332- php_swoole_fatal_error (E_WARNING, " the second parameter should be an array" );
341+ zend_throw_exception (
342+ swoole_exception_ce, " the second parameter should be an array" , SW_ERROR_INVALID_PARAMS);
333343 }
334344 SW_STRING_FORMAT (buf, " *%d\r\n " , 2 * zend_hash_num_elements (Z_ARRVAL_P (value)));
335345
@@ -347,7 +357,7 @@ static bool redis_response_format(String *buf, zend_long type, zval *value) {
347357 }
348358 ZEND_HASH_FOREACH_END ();
349359 } else {
350- php_swoole_error (E_WARNING , " Unknown type[%d]" , (int ) type);
360+ zend_throw_exception_ex (swoole_exception_ce, SW_ERROR_INVALID_PARAMS , " Unknown type[%d]" , (int ) type);
351361 return false ;
352362 }
353363
0 commit comments