@@ -307,7 +307,6 @@ static void php_memc_setMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke
307307static void php_memc_cas_impl (INTERNAL_FUNCTION_PARAMETERS , zend_bool by_key );
308308static void php_memc_delete_impl (INTERNAL_FUNCTION_PARAMETERS , zend_bool by_key );
309309static void php_memc_deleteMulti_impl (INTERNAL_FUNCTION_PARAMETERS , zend_bool by_key );
310- static void php_memc_incdec_impl (INTERNAL_FUNCTION_PARAMETERS , zend_bool incr );
311310static void php_memc_getDelayed_impl (INTERNAL_FUNCTION_PARAMETERS , zend_bool by_key );
312311static memcached_return php_memc_do_cache_callback (zval * memc_obj , zend_fcall_info * fci , zend_fcall_info_cache * fcc , char * key , size_t key_len , zval * value TSRMLS_DC );
313312static int php_memc_do_result_callback (zval * memc_obj , zend_fcall_info * fci , zend_fcall_info_cache * fcc , memcached_result_st * result TSRMLS_DC );
@@ -1598,34 +1597,27 @@ static void php_memc_deleteMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by
15981597}
15991598/* }}} */
16001599
1601- /* {{{ Memcached::increment(string key [, int delta ])
1602- Increments the value for the given key by delta, defaulting to 1 */
1603- PHP_METHOD (Memcached , increment )
1604- {
1605- php_memc_incdec_impl (INTERNAL_FUNCTION_PARAM_PASSTHRU , 1 );
1606- }
1607- /* }}} */
1608-
1609- /* {{{ Memcached::decrement(string key [, int delta ])
1610- Decrements the value for the given key by delta, defaulting to 1 */
1611- PHP_METHOD (Memcached , decrement )
1612- {
1613- php_memc_incdec_impl (INTERNAL_FUNCTION_PARAM_PASSTHRU , 0 );
1614- }
1615- /* }}} */
1616-
16171600/* {{{ -- php_memc_incdec_impl */
1618- static void php_memc_incdec_impl (INTERNAL_FUNCTION_PARAMETERS , zend_bool incr )
1601+ static void php_memc_incdec_impl (INTERNAL_FUNCTION_PARAMETERS , zend_bool by_key , zend_bool incr )
16191602{
1620- char * key = NULL ;
1621- int key_len = 0 ;
1603+ char * key , * server_key ;
1604+ int key_len , server_key_len ;
16221605 long offset = 1 ;
1623- uint64_t value ;
1606+ uint64_t value , initial = 0 ;
1607+ time_t expiry = 0 ;
16241608 memcached_return status ;
1609+ int n_args = ZEND_NUM_ARGS ();
1610+
16251611 MEMC_METHOD_INIT_VARS ;
16261612
1627- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "s|l" , & key , & key_len , & offset ) == FAILURE ) {
1628- return ;
1613+ if (!by_key ) {
1614+ if (zend_parse_parameters (n_args TSRMLS_CC , "s|lll" , & key , & key_len , & offset , & initial , & expiry ) == FAILURE ) {
1615+ return ;
1616+ }
1617+ } else {
1618+ if (zend_parse_parameters (n_args TSRMLS_CC , "ss|lll" , & server_key , & server_key_len , & key , & key_len , & offset , & initial , & expiry ) == FAILURE ) {
1619+ return ;
1620+ }
16291621 }
16301622
16311623 MEMC_METHOD_FETCH_OBJECT ;
@@ -1641,10 +1633,34 @@ static void php_memc_incdec_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool incr)
16411633 RETURN_FALSE ;
16421634 }
16431635
1644- if (incr ) {
1645- status = memcached_increment (m_obj -> memc , key , key_len , (unsigned int )offset , & value );
1636+ if ((!by_key && n_args < 3 ) || (by_key && n_args < 4 )) {
1637+ if (by_key ) {
1638+ if (incr ) {
1639+ status = memcached_increment_by_key (m_obj -> memc , server_key , server_key_len , key , key_len , (unsigned int )offset , & value );
1640+ } else {
1641+ status = memcached_decrement_by_key (m_obj -> memc , server_key , server_key_len , key , key_len , (unsigned int )offset , & value );
1642+ }
1643+ } else {
1644+ if (incr ) {
1645+ status = memcached_increment (m_obj -> memc , key , key_len , (unsigned int )offset , & value );
1646+ } else {
1647+ status = memcached_decrement (m_obj -> memc , key , key_len , (unsigned int )offset , & value );
1648+ }
1649+ }
16461650 } else {
1647- status = memcached_decrement (m_obj -> memc , key , key_len , (unsigned int )offset , & value );
1651+ if (by_key ) {
1652+ if (incr ) {
1653+ status = memcached_increment_with_initial_by_key (m_obj -> memc , server_key , server_key_len , key , key_len , (unsigned int )offset , initial , expiry , & value );
1654+ } else {
1655+ status = memcached_decrement_with_initial_by_key (m_obj -> memc , server_key , server_key_len , key , key_len , (unsigned int )offset , initial , expiry , & value );
1656+ }
1657+ } else {
1658+ if (incr ) {
1659+ status = memcached_increment_with_initial (m_obj -> memc , key , key_len , (unsigned int )offset , initial , expiry , & value );
1660+ } else {
1661+ status = memcached_decrement_with_initial (m_obj -> memc , key , key_len , (unsigned int )offset , initial , expiry , & value );
1662+ }
1663+ }
16481664 }
16491665
16501666 if (php_memc_handle_error (i_obj , status TSRMLS_CC ) < 0 ) {
@@ -1655,6 +1671,38 @@ static void php_memc_incdec_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool incr)
16551671}
16561672/* }}} */
16571673
1674+ /* {{{ Memcached::increment(string key [, int delta [, initial_value [, expiry time ] ] ])
1675+ Increments the value for the given key by delta, defaulting to 1 */
1676+ PHP_METHOD (Memcached , increment )
1677+ {
1678+ php_memc_incdec_impl (INTERNAL_FUNCTION_PARAM_PASSTHRU , 0 , 1 );
1679+ }
1680+ /* }}} */
1681+
1682+ /* {{{ Memcached::decrement(string key [, int delta [, initial_value [, expiry time ] ] ])
1683+ Decrements the value for the given key by delta, defaulting to 1 */
1684+ PHP_METHOD (Memcached , decrement )
1685+ {
1686+ php_memc_incdec_impl (INTERNAL_FUNCTION_PARAM_PASSTHRU , 0 , 0 );
1687+ }
1688+ /* }}} */
1689+
1690+ /* {{{ Memcached::decrementByKey(string server_key, string key [, int delta [, initial_value [, expiry time ] ] ])
1691+ Decrements by server the value for the given key by delta, defaulting to 1 */
1692+ PHP_METHOD (Memcached , decrementByKey )
1693+ {
1694+ php_memc_incdec_impl (INTERNAL_FUNCTION_PARAM_PASSTHRU , 1 , 0 );
1695+ }
1696+ /* }}} */
1697+
1698+ /* {{{ Memcached::increment(string server_key, string key [, int delta [, initial_value [, expiry time ] ] ])
1699+ Increments by server the value for the given key by delta, defaulting to 1 */
1700+ PHP_METHOD (Memcached , incrementByKey )
1701+ {
1702+ php_memc_incdec_impl (INTERNAL_FUNCTION_PARAM_PASSTHRU , 1 , 1 );
1703+ }
1704+ /* }}} */
1705+
16581706/* {{{ Memcached::addServer(string hostname, int port [, int weight ])
16591707 Adds the given memcache server to the list */
16601708PHP_METHOD (Memcached , addServer )
@@ -3168,11 +3216,31 @@ ZEND_END_ARG_INFO()
31683216ZEND_BEGIN_ARG_INFO_EX (arginfo_increment , 0 , 0 , 1 )
31693217 ZEND_ARG_INFO (0 , key )
31703218 ZEND_ARG_INFO (0 , offset )
3219+ ZEND_ARG_INFO (0 , initial_value )
3220+ ZEND_ARG_INFO (0 , expiry )
31713221ZEND_END_ARG_INFO ()
31723222
31733223ZEND_BEGIN_ARG_INFO_EX (arginfo_decrement , 0 , 0 , 1 )
31743224 ZEND_ARG_INFO (0 , key )
31753225 ZEND_ARG_INFO (0 , offset )
3226+ ZEND_ARG_INFO (0 , initial_value )
3227+ ZEND_ARG_INFO (0 , expiry )
3228+ ZEND_END_ARG_INFO ()
3229+
3230+ ZEND_BEGIN_ARG_INFO_EX (arginfo_incrementByKey , 0 , 0 , 2 )
3231+ ZEND_ARG_INFO (0 , server_key )
3232+ ZEND_ARG_INFO (0 , key )
3233+ ZEND_ARG_INFO (0 , offset )
3234+ ZEND_ARG_INFO (0 , initial_value )
3235+ ZEND_ARG_INFO (0 , expiry )
3236+ ZEND_END_ARG_INFO ()
3237+
3238+ ZEND_BEGIN_ARG_INFO_EX (arginfo_decrementByKey , 0 , 0 , 2 )
3239+ ZEND_ARG_INFO (0 , server_key )
3240+ ZEND_ARG_INFO (0 , key )
3241+ ZEND_ARG_INFO (0 , offset )
3242+ ZEND_ARG_INFO (0 , initial_value )
3243+ ZEND_ARG_INFO (0 , expiry )
31763244ZEND_END_ARG_INFO ()
31773245
31783246ZEND_BEGIN_ARG_INFO_EX (arginfo_flush , 0 , 0 , 0 )
@@ -3269,6 +3337,8 @@ static zend_function_entry memcached_class_methods[] = {
32693337
32703338 MEMC_ME (increment , arginfo_increment )
32713339 MEMC_ME (decrement , arginfo_decrement )
3340+ MEMC_ME (incrementByKey , arginfo_incrementByKey )
3341+ MEMC_ME (decrementByKey , arginfo_decrementByKey )
32723342
32733343 MEMC_ME (addServer , arginfo_addServer )
32743344 MEMC_ME (addServers , arginfo_addServers )
0 commit comments