mirror of
https://github.com/php-win-ext/php-memcached.git
synced 2026-03-24 00:52:18 +01:00
Add --enable-memcached-get-nulls to configure.
This options changes the behaviour of failing get requests. If a key is not found in memcached, then the return value is set to null instead of false. This only affects simple get and delayed fetch.
This commit is contained in:
10
config.m4
10
config.m4
@@ -16,6 +16,8 @@ PHP_ARG_ENABLE(memcached-igbinary, whether to enable memcached igbinary serializ
|
||||
|
||||
PHP_ARG_ENABLE(memcached-json, whether to enable memcached json serializer support,
|
||||
[ --enable-memcached-json Enable memcached json serializer support], no, no)
|
||||
PHP_ARG_ENABLE(memcached-get-nulls, whether to return nulls on get commands if not found,
|
||||
[ --enable-memcached-get-nulls Enable returning nulls from get commands if not found], no, no)
|
||||
|
||||
if test -z "$PHP_ZLIB_DIR"; then
|
||||
PHP_ARG_WITH(zlib-dir, for ZLIB,
|
||||
@@ -186,6 +188,14 @@ if test "$PHP_MEMCACHED" != "no"; then
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING([for get to return null if not found])
|
||||
if test "$PHP_MEMCACHED_GET_NULLS" != "no"; then
|
||||
AC_MSG_RESULT([enabled])
|
||||
AC_DEFINE(HAVE_MEMCACHED_GET_NULL, 1, [Whether to return nulls on get commands if not found])
|
||||
else
|
||||
AC_MSG_RESULT([disabled])
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING([for memcached session support])
|
||||
if test "$PHP_MEMCACHED_SESSION" != "no"; then
|
||||
AC_MSG_RESULT([enabled])
|
||||
|
||||
@@ -6,6 +6,12 @@
|
||||
|
||||
class Memcached {
|
||||
|
||||
/**
|
||||
* Error codes etc.
|
||||
*/
|
||||
|
||||
const GET_ERROR_RETURN_VALUE;
|
||||
|
||||
/**
|
||||
* Libmemcached behavior options.
|
||||
*/
|
||||
|
||||
@@ -153,6 +153,13 @@ typedef unsigned long int uint32_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MEMCACHED_GET_NULL
|
||||
/* return null value if value not found */
|
||||
#define RETURN_FROM_GET RETURN_NULL()
|
||||
#else
|
||||
#define RETURN_FROM_GET RETURN_FALSE
|
||||
#endif /* HAVE_MEMCACHED_GET_NULL */
|
||||
|
||||
/****************************************
|
||||
Structures and definitions
|
||||
****************************************/
|
||||
@@ -394,7 +401,7 @@ static void php_memc_get_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key)
|
||||
|
||||
if (key_len == 0) {
|
||||
i_obj->rescode = MEMCACHED_BAD_KEY_PROVIDED;
|
||||
RETURN_FALSE;
|
||||
RETURN_FROM_GET;
|
||||
}
|
||||
|
||||
if (cas_token) {
|
||||
@@ -412,7 +419,7 @@ static void php_memc_get_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key)
|
||||
status = memcached_mget_by_key(m_obj->memc, server_key, server_key_len, &key, &key_len, 1);
|
||||
|
||||
if (php_memc_handle_error(i_obj, status TSRMLS_CC) < 0) {
|
||||
RETURN_FALSE;
|
||||
RETURN_FROM_GET;
|
||||
}
|
||||
|
||||
status = MEMCACHED_SUCCESS;
|
||||
@@ -437,7 +444,7 @@ static void php_memc_get_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key)
|
||||
|
||||
if (php_memc_handle_error(i_obj, status TSRMLS_CC) < 0) {
|
||||
memcached_result_free(&result);
|
||||
RETURN_FALSE;
|
||||
RETURN_FROM_GET;
|
||||
}
|
||||
|
||||
/* if we have a callback, all processing is done */
|
||||
@@ -455,7 +462,7 @@ static void php_memc_get_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key)
|
||||
if (php_memc_zval_from_payload(return_value, payload, payload_len, flags TSRMLS_CC) < 0) {
|
||||
memcached_result_free(&result);
|
||||
i_obj->rescode = MEMC_RES_PAYLOAD_FAILURE;
|
||||
RETURN_FALSE;
|
||||
RETURN_FROM_GET;
|
||||
}
|
||||
|
||||
zval_dtor(cas_token);
|
||||
@@ -512,7 +519,7 @@ static void php_memc_get_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key)
|
||||
if (payload) {
|
||||
free(payload);
|
||||
}
|
||||
RETURN_FALSE;
|
||||
RETURN_FROM_GET;
|
||||
}
|
||||
|
||||
/* if memcached gave a value and there was no callback, payload may be NULL */
|
||||
@@ -521,7 +528,7 @@ static void php_memc_get_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_key)
|
||||
free(payload);
|
||||
if (rc < 0) {
|
||||
i_obj->rescode = MEMC_RES_PAYLOAD_FAILURE;
|
||||
RETURN_FALSE;
|
||||
RETURN_FROM_GET;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3075,6 +3082,8 @@ zend_module_entry memcached_module_entry = {
|
||||
static void php_memc_register_constants(INIT_FUNC_ARGS)
|
||||
{
|
||||
#define REGISTER_MEMC_CLASS_CONST_LONG(name, value) zend_declare_class_constant_long(php_memc_get_ce() , ZEND_STRS( #name ) - 1, value TSRMLS_CC)
|
||||
#define REGISTER_MEMC_CLASS_CONST_BOOL(name, value) zend_declare_class_constant_bool(php_memc_get_ce() , ZEND_STRS( #name ) - 1, value TSRMLS_CC)
|
||||
#define REGISTER_MEMC_CLASS_CONST_NULL(name) zend_declare_class_constant_null(php_memc_get_ce() , ZEND_STRS( #name ) - 1)
|
||||
|
||||
/*
|
||||
* Class options
|
||||
@@ -3183,6 +3192,15 @@ static void php_memc_register_constants(INIT_FUNC_ARGS)
|
||||
REGISTER_MEMC_CLASS_CONST_LONG(GET_PRESERVE_ORDER, MEMC_GET_PRESERVE_ORDER);
|
||||
|
||||
#undef REGISTER_MEMC_CLASS_CONST_LONG
|
||||
|
||||
/*
|
||||
* Return value from simple get errors
|
||||
*/
|
||||
#ifdef HAVE_MEMCACHED_GET_NULL
|
||||
REGISTER_MEMC_CLASS_CONST_NULL(GET_ERROR_RETURN_VALUE);
|
||||
#else
|
||||
REGISTER_MEMC_CLASS_CONST_BOOL(GET_ERROR_RETURN_VALUE, 0);
|
||||
#endif
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
@@ -11,8 +11,10 @@ $m->set('eisaleeoo', "foo");
|
||||
$m->delete('eisaleeoo');
|
||||
$v = $m->get('eisaleeoo');
|
||||
|
||||
if ($v !== false) {
|
||||
echo "Wanted a false value from get. Got:\n";
|
||||
if ($v !== Memcached::GET_ERROR_RETURN_VALUE) {
|
||||
echo "Wanted: ";
|
||||
var_dump(Memcached::GET_ERROR_RETURN_VALUE);
|
||||
echo "Got: ";
|
||||
var_dump($v);
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -15,9 +15,9 @@ if (!$set || $v != 'foo') {
|
||||
sleep(3);
|
||||
$v = $m->get('will_expire');
|
||||
|
||||
if ($v !== false) {
|
||||
echo "Wanted a:\n";
|
||||
var_dump(false);
|
||||
if ($v !== Memcached::GET_ERROR_RETURN_VALUE) {
|
||||
echo "Wanted:\n";
|
||||
var_dump(Memcached::GET_ERROR_RETURN_VALUE);
|
||||
echo "from get of expired value. Got:\n";
|
||||
var_dump($v);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user