Add clearLastError

This commit is contained in:
Nicolas Favre-Felix
2012-09-09 22:09:27 +01:00
parent 6153477c4f
commit 5855cfc2ca
4 changed files with 50 additions and 0 deletions
+18
View File
@@ -2484,6 +2484,24 @@ $err = $redis->getLastError();
// "ERR Error compiling script (new function): user_script:1: '=' expected near '-'"
</pre>
## clearLastError
##### Description
Clear the last error message
##### Parameters
*none*
##### Return Value
*BOOL* TRUE
##### Examples
<pre>
$redis->set('x', 'a');
$redis->incr('x');
$err = $redis->getLastError();
// "ERR value is not an integer or out of range"
$redis->clearLastError();
$err = $redis->getLastError();
// NULL
</pre>
## _prefix
##### Description
A utility method to prefix the value with the prefix setting for phpredis.
+1
View File
@@ -139,6 +139,7 @@ PHP_METHOD(Redis, migrate);
PHP_METHOD(Redis, time);
PHP_METHOD(Redis, getLastError);
PHP_METHOD(Redis, clearLastError);
PHP_METHOD(Redis, _prefix);
PHP_METHOD(Redis, _unserialize);
+27
View File
@@ -219,6 +219,7 @@ static zend_function_entry redis_functions[] = {
PHP_ME(Redis, migrate, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Redis, getLastError, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Redis, clearLastError, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Redis, _prefix, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Redis, _unserialize, NULL, ZEND_ACC_PUBLIC)
@@ -6161,6 +6162,32 @@ PHP_METHOD(Redis, getLastError) {
}
}
/*
* {{{ proto Redis::clearLastError()
*/
PHP_METHOD(Redis, clearLastError) {
zval *object;
RedisSock *redis_sock;
// Grab our object
if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, redis_ce) == FAILURE) {
RETURN_FALSE;
}
// Grab socket
if(redis_sock_get(object, &redis_sock TSRMLS_CC, 0) < 0) {
RETURN_FALSE;
}
// Clear error message
if(redis_sock->err) {
efree(redis_sock->err);
}
redis_sock->err = NULL;
RETURN_TRUE;
}
/*
* {{{ proto Redis::time()
*/
+4
View File
@@ -3032,6 +3032,10 @@ class Redis_Test extends TestSuite
$incrError = $this->redis->getLastError();
$this->assertTrue($incrError !== $evalError); // error has changed
$this->assertTrue(strlen($incrError) > 0);
// clear error
$this->redis->clearLastError();
$this->assertTrue($this->redis->getLastError() === NULL);
}
// Helper function to compare nested results -- from the php.net array_diff page, I believe