@@ -1325,88 +1325,85 @@ PHP_METHOD(Redis, decrBy){
1325
1325
*/
1326
1326
PHP_METHOD (Redis , getMultiple )
1327
1327
{
1328
- zval * object , * array , * * data ;
1329
- HashTable * arr_hash ;
1330
- HashPosition pointer ;
1328
+ zval * object , * z_args , * * z_ele ;
1329
+ HashTable * hash ;
1330
+ HashPosition ptr ;
1331
1331
RedisSock * redis_sock ;
1332
- char * cmd = "" , * old_cmd = NULL ;
1333
- int cmd_len = 0 , array_count , elements = 1 ;
1332
+ smart_str cmd = { 0 } ;
1333
+ int arg_count ;
1334
1334
1335
- if (zend_parse_method_parameters (ZEND_NUM_ARGS () TSRMLS_CC , getThis (), "Oa" ,
1336
- & object , redis_ce , & array ) == FAILURE ) {
1335
+ // Make sure we have proper arguments
1336
+ if (zend_parse_method_parameters (ZEND_NUM_ARGS () TSRMLS_CC , getThis (), "Oa" ,
1337
+ & object , redis_ce , & z_args ) == FAILURE ) {
1337
1338
RETURN_FALSE ;
1338
1339
}
1339
1340
1340
- if (redis_sock_get (object , & redis_sock TSRMLS_CC , 0 ) < 0 ) {
1341
+ // We'll need the socket
1342
+ if (redis_sock_get (object , & redis_sock TSRMLS_CC , 0 ) < 0 ) {
1341
1343
RETURN_FALSE ;
1342
1344
}
1343
1345
1344
- arr_hash = Z_ARRVAL_P ( array );
1345
- array_count = zend_hash_num_elements ( arr_hash );
1346
+ // Grab our array
1347
+ hash = Z_ARRVAL_P ( z_args );
1346
1348
1347
- if (array_count == 0 ) {
1349
+ // We don't need to do anything if there aren't any keys
1350
+ if ((arg_count = zend_hash_num_elements (hash )) == 0 ) {
1348
1351
RETURN_FALSE ;
1349
1352
}
1350
1353
1351
- for (zend_hash_internal_pointer_reset_ex (arr_hash , & pointer );
1352
- zend_hash_get_current_data_ex (arr_hash , (void * * ) & data ,
1353
- & pointer ) == SUCCESS ;
1354
- zend_hash_move_forward_ex (arr_hash , & pointer )) {
1354
+ // Build our command header
1355
+ redis_cmd_init_sstr (& cmd , arg_count , "MGET" , 4 );
1355
1356
1357
+ // Iterate through and grab our keys
1358
+ for (zend_hash_internal_pointer_reset_ex (hash , & ptr );
1359
+ zend_hash_get_current_data_ex (hash , (void * * )& z_ele , & ptr ) == SUCCESS ;
1360
+ zend_hash_move_forward_ex (hash , & ptr ))
1361
+ {
1356
1362
char * key ;
1357
- int key_len ;
1363
+ int key_len , key_free ;
1358
1364
zval * z_tmp = NULL ;
1359
- char * old_cmd ;
1360
- int key_free ;
1361
1365
1362
- if (Z_TYPE_PP (data ) == IS_STRING ) {
1363
- key = Z_STRVAL_PP (data );
1364
- key_len = Z_STRLEN_PP (data );
1365
- } else { /* not a string, copy and convert. */
1366
+ // If the key isn't a string, turn it into one
1367
+ if (Z_TYPE_PP (z_ele ) == IS_STRING ) {
1368
+ key = Z_STRVAL_PP (z_ele );
1369
+ key_len = Z_STRLEN_PP (z_ele );
1370
+ } else {
1366
1371
MAKE_STD_ZVAL (z_tmp );
1367
- * z_tmp = * * data ;
1372
+ * z_tmp = * * z_ele ;
1368
1373
zval_copy_ctor (z_tmp );
1369
1374
convert_to_string (z_tmp );
1370
1375
1371
1376
key = Z_STRVAL_P (z_tmp );
1372
1377
key_len = Z_STRLEN_P (z_tmp );
1373
1378
}
1374
- old_cmd = NULL ;
1375
- if (* cmd ) {
1376
- old_cmd = cmd ;
1377
- }
1378
- key_free = redis_key_prefix (redis_sock , & key , & key_len TSRMLS_CC );
1379
- cmd_len = redis_cmd_format (& cmd , "%s$%d" _NL "%s" _NL
1380
- , cmd , cmd_len
1381
- , key_len , key , key_len );
1382
1379
1383
- if (key_free ) efree (key );
1380
+ // Apply key prefix if necissary
1381
+ key_free = redis_key_prefix (redis_sock , & key , & key_len TSRMLS_CC );
1384
1382
1385
- if (old_cmd ) {
1386
- efree (old_cmd );
1387
- }
1388
- elements ++ ;
1383
+ // Append this key to our command
1384
+ redis_cmd_append_sstr (& cmd , key , key_len );
1385
+
1386
+ // Free our key if it was prefixed
1387
+ if (key_free ) efree (key );
1388
+
1389
+ // Free oour temporary ZVAL if we converted from a non-string
1389
1390
if (z_tmp ) {
1390
1391
zval_dtor (z_tmp );
1391
1392
efree (z_tmp );
1393
+ z_tmp = NULL ;
1392
1394
}
1393
1395
}
1394
1396
1395
- old_cmd = cmd ;
1396
- cmd_len = redis_cmd_format (& cmd , "*%d" _NL "$4" _NL "MGET" _NL "%s" , elements , cmd , cmd_len );
1397
- efree (old_cmd );
1398
-
1399
- REDIS_PROCESS_REQUEST (redis_sock , cmd , cmd_len );
1397
+ // Kick off our command
1398
+ REDIS_PROCESS_REQUEST (redis_sock , cmd .c , cmd .len );
1400
1399
IF_ATOMIC () {
1401
- if (redis_sock_read_multibulk_reply (INTERNAL_FUNCTION_PARAM_PASSTHRU ,
1402
- redis_sock , NULL , NULL ) < 0 ) {
1403
- RETURN_FALSE ;
1404
- }
1400
+ if (redis_sock_read_multibulk_reply (INTERNAL_FUNCTION_PARAM_PASSTHRU ,
1401
+ redis_sock , NULL , NULL ) < 0 ) {
1402
+ RETURN_FALSE ;
1403
+ }
1405
1404
}
1406
1405
REDIS_PROCESS_RESPONSE (redis_sock_read_multibulk_reply );
1407
-
1408
1406
}
1409
- /* }}} */
1410
1407
1411
1408
/* {{{ proto boolean Redis::exists(string key)
1412
1409
*/
0 commit comments