mirror of
https://github.com/php-win-ext/phpredis.git
synced 2026-04-28 11:13:16 +02:00
Add clearLastError
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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()
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user