@@ -307,7 +307,6 @@ static void php_memc_setMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke
307
307
static void php_memc_cas_impl (INTERNAL_FUNCTION_PARAMETERS , zend_bool by_key );
308
308
static void php_memc_delete_impl (INTERNAL_FUNCTION_PARAMETERS , zend_bool by_key );
309
309
static 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 );
311
310
static void php_memc_getDelayed_impl (INTERNAL_FUNCTION_PARAMETERS , zend_bool by_key );
312
311
static 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 );
313
312
static 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
1598
1597
}
1599
1598
/* }}} */
1600
1599
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
-
1617
1600
/* {{{ -- 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 )
1619
1602
{
1620
- char * key = NULL ;
1621
- int key_len = 0 ;
1603
+ char * key , * server_key ;
1604
+ int key_len , server_key_len ;
1622
1605
long offset = 1 ;
1623
- uint64_t value ;
1606
+ uint64_t value , initial = 0 ;
1607
+ time_t expiry = 0 ;
1624
1608
memcached_return status ;
1609
+ int n_args = ZEND_NUM_ARGS ();
1610
+
1625
1611
MEMC_METHOD_INIT_VARS ;
1626
1612
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
+ }
1629
1621
}
1630
1622
1631
1623
MEMC_METHOD_FETCH_OBJECT ;
@@ -1641,10 +1633,34 @@ static void php_memc_incdec_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool incr)
1641
1633
RETURN_FALSE ;
1642
1634
}
1643
1635
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
+ }
1646
1650
} 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
+ }
1648
1664
}
1649
1665
1650
1666
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)
1655
1671
}
1656
1672
/* }}} */
1657
1673
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
+
1658
1706
/* {{{ Memcached::addServer(string hostname, int port [, int weight ])
1659
1707
Adds the given memcache server to the list */
1660
1708
PHP_METHOD (Memcached , addServer )
@@ -3168,11 +3216,31 @@ ZEND_END_ARG_INFO()
3168
3216
ZEND_BEGIN_ARG_INFO_EX (arginfo_increment , 0 , 0 , 1 )
3169
3217
ZEND_ARG_INFO (0 , key )
3170
3218
ZEND_ARG_INFO (0 , offset )
3219
+ ZEND_ARG_INFO (0 , initial_value )
3220
+ ZEND_ARG_INFO (0 , expiry )
3171
3221
ZEND_END_ARG_INFO ()
3172
3222
3173
3223
ZEND_BEGIN_ARG_INFO_EX (arginfo_decrement , 0 , 0 , 1 )
3174
3224
ZEND_ARG_INFO (0 , key )
3175
3225
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 )
3176
3244
ZEND_END_ARG_INFO ()
3177
3245
3178
3246
ZEND_BEGIN_ARG_INFO_EX (arginfo_flush , 0 , 0 , 0 )
@@ -3269,6 +3337,8 @@ static zend_function_entry memcached_class_methods[] = {
3269
3337
3270
3338
MEMC_ME (increment , arginfo_increment )
3271
3339
MEMC_ME (decrement , arginfo_decrement )
3340
+ MEMC_ME (incrementByKey , arginfo_incrementByKey )
3341
+ MEMC_ME (decrementByKey , arginfo_decrementByKey )
3272
3342
3273
3343
MEMC_ME (addServer , arginfo_addServer )
3274
3344
MEMC_ME (addServers , arginfo_addServers )
0 commit comments