Skip to content
This repository
Browse code

Various fixes.

- Rename certain parameters in the API to be more clear.
- Allow only strings as the append/prepend value.
- Remove expiration parameter from append/prepend.
  • Loading branch information...
commit 79100dee006d74a3964b1dc8cd6bed8815c1e7e7 1 parent c410cc6
andrei authored

Showing 2 changed files with 51 additions and 26 deletions. Show diff stats Hide diff stats

  1. +5 5 memcached-api.php
  2. +46 21 php_memcached.c
10 memcached-api.php
@@ -95,9 +95,9 @@ public function set( $key, $value, $expiration = 0 ) {}
95 95
96 96 public function setByKey( $server_key, $key, $value, $expiration = 0 ) {}
97 97
98   - public function setMulti( $array, $expiration = 0 ) {}
  98 + public function setMulti( array $items, $expiration = 0 ) {}
99 99
100   - public function setMultiByKey( $server_key, $array, $expiration = 0 ) {}
  100 + public function setMultiByKey( $server_key, array $items, $expiration = 0 ) {}
101 101
102 102 public function cas( $token, $key, $value, $expiration = 0 ) {}
103 103
@@ -119,9 +119,9 @@ public function replace( $key, $value, $expiration = 0 ) {}
119 119
120 120 public function replaceByKey( $serve_key, $key, $value, $expiration = 0 ) {}
121 121
122   - public function delete( $key, $expiration = 0 ) {}
  122 + public function delete( $key, $time = 0 ) {}
123 123
124   - public function deleteByKey( $key, $expiration = 0 ) {}
  124 + public function deleteByKey( $key, $time = 0 ) {}
125 125
126 126 public function increment( $key, $offset = 1) {}
127 127
@@ -139,7 +139,7 @@ public function getServerList( ) {}
139 139
140 140 public function getServerByKey( $server_key ) {}
141 141
142   - public function flush( ) {}
  142 + public function flush( $delay = 0 ) {}
143 143
144 144 public function getResultCode( ) {}
145 145
67 php_memcached.c
@@ -17,6 +17,8 @@
17 17 /* $ Id: $ */
18 18
19 19 /* TODO
  20 + * - set LIBKETAMA_COMPATIBLE as the default?
  21 + * - add payload flag for IS_BOOL?
20 22 */
21 23
22 24 #ifdef HAVE_CONFIG_H
@@ -837,16 +839,16 @@ PHP_METHOD(Memcached, setByKey)
837 839 }
838 840 /* }}} */
839 841
840   -/* {{{ Memcached::setMulti(array entries [, int expiration ])
841   - Sets the keys/values specified in the entries array */
  842 +/* {{{ Memcached::setMulti(array items [, int expiration ])
  843 + Sets the keys/values specified in the items array */
842 844 PHP_METHOD(Memcached, setMulti)
843 845 {
844 846 php_memc_setMulti_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
845 847 }
846 848 /* }}} */
847 849
848   -/* {{{ Memcached::setMultiByKey(string server_key, array entries [, int expiration ])
849   - Sets the keys/values specified in the entries array on the server identified by the given server key */
  850 +/* {{{ Memcached::setMultiByKey(string server_key, array items [, int expiration ])
  851 + Sets the keys/values specified in the items array on the server identified by the given server key */
850 852 PHP_METHOD(Memcached, setMultiByKey)
851 853 {
852 854 php_memc_setMulti_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
@@ -991,6 +993,8 @@ static void php_memc_store_impl(INTERNAL_FUNCTION_PARAMETERS, int op, zend_bool
991 993 int key_len = 0;
992 994 char *server_key = NULL;
993 995 int server_key_len = 0;
  996 + char *s_value = NULL;
  997 + int s_value_len = 0;
994 998 zval *value;
995 999 time_t expiration = 0;
996 1000 char *payload;
@@ -1000,14 +1004,32 @@ static void php_memc_store_impl(INTERNAL_FUNCTION_PARAMETERS, int op, zend_bool
1000 1004 MEMC_METHOD_INIT_VARS;
1001 1005
1002 1006 if (by_key) {
1003   - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssz|l", &server_key,
1004   - &server_key_len, &key, &key_len, &value, &expiration) == FAILURE) {
1005   - return;
  1007 + if (op == MEMC_OP_APPEND || op == MEMC_OP_PREPEND) {
  1008 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &server_key,
  1009 + &server_key_len, &key, &key_len, &s_value, &s_value_len, &expiration) == FAILURE) {
  1010 + return;
  1011 + }
  1012 + MAKE_STD_ZVAL(value);
  1013 + ZVAL_STRINGL(value, s_value, s_value_len, 1);
  1014 + } else {
  1015 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssz|l", &server_key,
  1016 + &server_key_len, &key, &key_len, &value, &expiration) == FAILURE) {
  1017 + return;
  1018 + }
1006 1019 }
1007 1020 } else {
1008   - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|l", &key, &key_len,
1009   - &value, &expiration) == FAILURE) {
1010   - return;
  1021 + if (op == MEMC_OP_APPEND || op == MEMC_OP_PREPEND) {
  1022 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &key, &key_len,
  1023 + &s_value, &s_value_len) == FAILURE) {
  1024 + return;
  1025 + }
  1026 + MAKE_STD_ZVAL(value);
  1027 + ZVAL_STRINGL(value, s_value, s_value_len, 1);
  1028 + } else {
  1029 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|l", &key, &key_len,
  1030 + &value, &expiration) == FAILURE) {
  1031 + return;
  1032 + }
1011 1033 }
1012 1034 server_key = key;
1013 1035 server_key_len = key_len;
@@ -1035,6 +1057,9 @@ static void php_memc_store_impl(INTERNAL_FUNCTION_PARAMETERS, int op, zend_bool
1035 1057 }
1036 1058
1037 1059 payload = php_memc_zval_to_payload(value, &payload_len, &flags TSRMLS_CC);
  1060 + if (op == MEMC_OP_APPEND || op == MEMC_OP_PREPEND) {
  1061 + zval_ptr_dtor(&value);
  1062 + }
1038 1063 if (payload == NULL) {
1039 1064 MEMC_G(rescode) = MEMC_RES_PAYLOAD_FAILURE;
1040 1065 RETURN_FALSE;
@@ -1158,7 +1183,7 @@ static void php_memc_cas_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key)
1158 1183 }
1159 1184 /* }}} */
1160 1185
1161   -/* {{{ Memcached::delete(string key [, int expiration ])
  1186 +/* {{{ Memcached::delete(string key [, int time ])
1162 1187 Deletes the given key */
1163 1188 PHP_METHOD(Memcached, delete)
1164 1189 {
@@ -1166,7 +1191,7 @@ PHP_METHOD(Memcached, delete)
1166 1191 }
1167 1192 /* }}} */
1168 1193
1169   -/* {{{ Memcached::deleteByKey(string server_key, string key [, int expiration ])
  1194 +/* {{{ Memcached::deleteByKey(string server_key, string key [, int time ])
1170 1195 Deletes the given key from the server identified by the server key */
1171 1196 PHP_METHOD(Memcached, deleteByKey)
1172 1197 {
@@ -1501,22 +1526,22 @@ PHP_METHOD(Memcached, getStats)
1501 1526 }
1502 1527 /* }}} */
1503 1528
1504   -/* {{{ Memcached::flush([ int expiration ])
  1529 +/* {{{ Memcached::flush([ int delay ])
1505 1530 Flushes the data on all the servers */
1506 1531 static PHP_METHOD(Memcached, flush)
1507 1532 {
1508   - time_t expiration = 0;
  1533 + time_t delay = 0;
1509 1534 memcached_return status;
1510 1535 MEMC_METHOD_INIT_VARS;
1511 1536
1512   - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &expiration) == FAILURE) {
  1537 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &delay) == FAILURE) {
1513 1538 return;
1514 1539 }
1515 1540
1516 1541 MEMC_METHOD_FETCH_OBJECT;
1517 1542 MEMC_G(rescode) = MEMCACHED_SUCCESS;
1518 1543
1519   - status = memcached_flush(i_obj->memc, expiration);
  1544 + status = memcached_flush(i_obj->memc, delay);
1520 1545 if (php_memc_handle_error(status TSRMLS_CC) < 0) {
1521 1546 RETURN_FALSE;
1522 1547 }
@@ -2302,14 +2327,14 @@ ZEND_END_ARG_INFO()
2302 2327
2303 2328 static
2304 2329 ZEND_BEGIN_ARG_INFO_EX(arginfo_setMulti, 0, 0, 1)
2305   - ZEND_ARG_ARRAY_INFO(0, entries, 0)
  2330 + ZEND_ARG_ARRAY_INFO(0, items, 0)
2306 2331 ZEND_ARG_INFO(0, expiration)
2307 2332 ZEND_END_ARG_INFO()
2308 2333
2309 2334 static
2310 2335 ZEND_BEGIN_ARG_INFO_EX(arginfo_setMultiByKey, 0, 0, 2)
2311 2336 ZEND_ARG_INFO(0, server_key)
2312   - ZEND_ARG_ARRAY_INFO(0, entries, 0)
  2337 + ZEND_ARG_ARRAY_INFO(0, items, 0)
2313 2338 ZEND_ARG_INFO(0, expiration)
2314 2339 ZEND_END_ARG_INFO()
2315 2340
@@ -2393,14 +2418,14 @@ ZEND_END_ARG_INFO()
2393 2418 static
2394 2419 ZEND_BEGIN_ARG_INFO_EX(arginfo_delete, 0, 0, 1)
2395 2420 ZEND_ARG_INFO(0, key)
2396   - ZEND_ARG_INFO(0, expiration)
  2421 + ZEND_ARG_INFO(0, time)
2397 2422 ZEND_END_ARG_INFO()
2398 2423
2399 2424 static
2400 2425 ZEND_BEGIN_ARG_INFO_EX(arginfo_deleteByKey, 0, 0, 2)
2401 2426 ZEND_ARG_INFO(0, server_key)
2402 2427 ZEND_ARG_INFO(0, key)
2403   - ZEND_ARG_INFO(0, expiration)
  2428 + ZEND_ARG_INFO(0, time)
2404 2429 ZEND_END_ARG_INFO()
2405 2430
2406 2431 static
@@ -2417,7 +2442,7 @@ ZEND_END_ARG_INFO()
2417 2442
2418 2443 static
2419 2444 ZEND_BEGIN_ARG_INFO_EX(arginfo_flush, 0, 0, 0)
2420   - ZEND_ARG_INFO(0, expiration)
  2445 + ZEND_ARG_INFO(0, delay)
2421 2446 ZEND_END_ARG_INFO()
2422 2447
2423 2448 static

0 comments on commit 79100de

Please sign in to comment.
Something went wrong with that request. Please try again.