Skip to content

Commit 79100de

Browse files
author
andrei
committed
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.
1 parent c410cc6 commit 79100de

File tree

2 files changed

+51
-26
lines changed

2 files changed

+51
-26
lines changed

memcached-api.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ public function set( $key, $value, $expiration = 0 ) {}
9595

9696
public function setByKey( $server_key, $key, $value, $expiration = 0 ) {}
9797

98-
public function setMulti( $array, $expiration = 0 ) {}
98+
public function setMulti( array $items, $expiration = 0 ) {}
9999

100-
public function setMultiByKey( $server_key, $array, $expiration = 0 ) {}
100+
public function setMultiByKey( $server_key, array $items, $expiration = 0 ) {}
101101

102102
public function cas( $token, $key, $value, $expiration = 0 ) {}
103103

@@ -119,9 +119,9 @@ public function replace( $key, $value, $expiration = 0 ) {}
119119

120120
public function replaceByKey( $serve_key, $key, $value, $expiration = 0 ) {}
121121

122-
public function delete( $key, $expiration = 0 ) {}
122+
public function delete( $key, $time = 0 ) {}
123123

124-
public function deleteByKey( $key, $expiration = 0 ) {}
124+
public function deleteByKey( $key, $time = 0 ) {}
125125

126126
public function increment( $key, $offset = 1) {}
127127

@@ -139,7 +139,7 @@ public function getServerList( ) {}
139139

140140
public function getServerByKey( $server_key ) {}
141141

142-
public function flush( ) {}
142+
public function flush( $delay = 0 ) {}
143143

144144
public function getResultCode( ) {}
145145

php_memcached.c

+46-21
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
/* $ Id: $ */
1818

1919
/* TODO
20+
* - set LIBKETAMA_COMPATIBLE as the default?
21+
* - add payload flag for IS_BOOL?
2022
*/
2123

2224
#ifdef HAVE_CONFIG_H
@@ -837,16 +839,16 @@ PHP_METHOD(Memcached, setByKey)
837839
}
838840
/* }}} */
839841

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 */
842844
PHP_METHOD(Memcached, setMulti)
843845
{
844846
php_memc_setMulti_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
845847
}
846848
/* }}} */
847849

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 */
850852
PHP_METHOD(Memcached, setMultiByKey)
851853
{
852854
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
991993
int key_len = 0;
992994
char *server_key = NULL;
993995
int server_key_len = 0;
996+
char *s_value = NULL;
997+
int s_value_len = 0;
994998
zval *value;
995999
time_t expiration = 0;
9961000
char *payload;
@@ -1000,14 +1004,32 @@ static void php_memc_store_impl(INTERNAL_FUNCTION_PARAMETERS, int op, zend_bool
10001004
MEMC_METHOD_INIT_VARS;
10011005

10021006
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+
}
10061019
}
10071020
} 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+
}
10111033
}
10121034
server_key = key;
10131035
server_key_len = key_len;
@@ -1035,6 +1057,9 @@ static void php_memc_store_impl(INTERNAL_FUNCTION_PARAMETERS, int op, zend_bool
10351057
}
10361058

10371059
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+
}
10381063
if (payload == NULL) {
10391064
MEMC_G(rescode) = MEMC_RES_PAYLOAD_FAILURE;
10401065
RETURN_FALSE;
@@ -1158,15 +1183,15 @@ static void php_memc_cas_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key)
11581183
}
11591184
/* }}} */
11601185

1161-
/* {{{ Memcached::delete(string key [, int expiration ])
1186+
/* {{{ Memcached::delete(string key [, int time ])
11621187
Deletes the given key */
11631188
PHP_METHOD(Memcached, delete)
11641189
{
11651190
php_memc_delete_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
11661191
}
11671192
/* }}} */
11681193

1169-
/* {{{ Memcached::deleteByKey(string server_key, string key [, int expiration ])
1194+
/* {{{ Memcached::deleteByKey(string server_key, string key [, int time ])
11701195
Deletes the given key from the server identified by the server key */
11711196
PHP_METHOD(Memcached, deleteByKey)
11721197
{
@@ -1501,22 +1526,22 @@ PHP_METHOD(Memcached, getStats)
15011526
}
15021527
/* }}} */
15031528

1504-
/* {{{ Memcached::flush([ int expiration ])
1529+
/* {{{ Memcached::flush([ int delay ])
15051530
Flushes the data on all the servers */
15061531
static PHP_METHOD(Memcached, flush)
15071532
{
1508-
time_t expiration = 0;
1533+
time_t delay = 0;
15091534
memcached_return status;
15101535
MEMC_METHOD_INIT_VARS;
15111536

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) {
15131538
return;
15141539
}
15151540

15161541
MEMC_METHOD_FETCH_OBJECT;
15171542
MEMC_G(rescode) = MEMCACHED_SUCCESS;
15181543

1519-
status = memcached_flush(i_obj->memc, expiration);
1544+
status = memcached_flush(i_obj->memc, delay);
15201545
if (php_memc_handle_error(status TSRMLS_CC) < 0) {
15211546
RETURN_FALSE;
15221547
}
@@ -2302,14 +2327,14 @@ ZEND_END_ARG_INFO()
23022327

23032328
static
23042329
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)
23062331
ZEND_ARG_INFO(0, expiration)
23072332
ZEND_END_ARG_INFO()
23082333

23092334
static
23102335
ZEND_BEGIN_ARG_INFO_EX(arginfo_setMultiByKey, 0, 0, 2)
23112336
ZEND_ARG_INFO(0, server_key)
2312-
ZEND_ARG_ARRAY_INFO(0, entries, 0)
2337+
ZEND_ARG_ARRAY_INFO(0, items, 0)
23132338
ZEND_ARG_INFO(0, expiration)
23142339
ZEND_END_ARG_INFO()
23152340

@@ -2393,14 +2418,14 @@ ZEND_END_ARG_INFO()
23932418
static
23942419
ZEND_BEGIN_ARG_INFO_EX(arginfo_delete, 0, 0, 1)
23952420
ZEND_ARG_INFO(0, key)
2396-
ZEND_ARG_INFO(0, expiration)
2421+
ZEND_ARG_INFO(0, time)
23972422
ZEND_END_ARG_INFO()
23982423

23992424
static
24002425
ZEND_BEGIN_ARG_INFO_EX(arginfo_deleteByKey, 0, 0, 2)
24012426
ZEND_ARG_INFO(0, server_key)
24022427
ZEND_ARG_INFO(0, key)
2403-
ZEND_ARG_INFO(0, expiration)
2428+
ZEND_ARG_INFO(0, time)
24042429
ZEND_END_ARG_INFO()
24052430

24062431
static
@@ -2417,7 +2442,7 @@ ZEND_END_ARG_INFO()
24172442

24182443
static
24192444
ZEND_BEGIN_ARG_INFO_EX(arginfo_flush, 0, 0, 0)
2420-
ZEND_ARG_INFO(0, expiration)
2445+
ZEND_ARG_INFO(0, delay)
24212446
ZEND_END_ARG_INFO()
24222447

24232448
static

0 commit comments

Comments
 (0)