@@ -273,6 +273,9 @@ static void redis_response_format_array_item(String *buf, zval *item) {
273
273
redis_response_format (buf, Redis::REPLY_MAP, item);
274
274
}
275
275
break ;
276
+ case IS_NULL:
277
+ redis_response_format (buf, Redis::REPLY_NIL, item);
278
+ break ;
276
279
default :
277
280
redis_response_format (buf, Redis::REPLY_STRING, item);
278
281
break ;
@@ -299,23 +302,29 @@ static bool redis_response_format(String *buf, zend_long type, zval *value) {
299
302
} else if (type == Redis::REPLY_STRING) {
300
303
if (!value) {
301
304
_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 );
303
306
return false ;
304
307
}
305
308
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);
308
313
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);
309
320
}
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);
313
321
} else if (type == Redis::REPLY_SET) {
314
322
if (!value) {
315
323
goto _no_value;
316
324
}
317
325
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);
319
328
}
320
329
SW_STRING_FORMAT (buf, " *%d\r\n " , zend_hash_num_elements (Z_ARRVAL_P (value)));
321
330
@@ -329,7 +338,8 @@ static bool redis_response_format(String *buf, zend_long type, zval *value) {
329
338
goto _no_value;
330
339
}
331
340
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);
333
343
}
334
344
SW_STRING_FORMAT (buf, " *%d\r\n " , 2 * zend_hash_num_elements (Z_ARRVAL_P (value)));
335
345
@@ -347,7 +357,7 @@ static bool redis_response_format(String *buf, zend_long type, zval *value) {
347
357
}
348
358
ZEND_HASH_FOREACH_END ();
349
359
} 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);
351
361
return false ;
352
362
}
353
363
0 commit comments