Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5855cfc

Browse files
committed
Add clearLastError
1 parent 6153477 commit 5855cfc

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

README.markdown

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2484,6 +2484,24 @@ $err = $redis->getLastError();
24842484
// "ERR Error compiling script (new function): user_script:1: '=' expected near '-'"
24852485
</pre>
24862486

2487+
## clearLastError
2488+
##### Description
2489+
Clear the last error message
2490+
##### Parameters
2491+
*none*
2492+
##### Return Value
2493+
*BOOL* TRUE
2494+
##### Examples
2495+
<pre>
2496+
$redis->set('x', 'a');
2497+
$redis->incr('x');
2498+
$err = $redis->getLastError();
2499+
// "ERR value is not an integer or out of range"
2500+
$redis->clearLastError();
2501+
$err = $redis->getLastError();
2502+
// NULL
2503+
</pre>
2504+
24872505
## _prefix
24882506
##### Description
24892507
A utility method to prefix the value with the prefix setting for phpredis.

php_redis.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ PHP_METHOD(Redis, migrate);
139139
PHP_METHOD(Redis, time);
140140

141141
PHP_METHOD(Redis, getLastError);
142+
PHP_METHOD(Redis, clearLastError);
142143
PHP_METHOD(Redis, _prefix);
143144
PHP_METHOD(Redis, _unserialize);
144145

redis.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ static zend_function_entry redis_functions[] = {
219219
PHP_ME(Redis, migrate, NULL, ZEND_ACC_PUBLIC)
220220

221221
PHP_ME(Redis, getLastError, NULL, ZEND_ACC_PUBLIC)
222+
PHP_ME(Redis, clearLastError, NULL, ZEND_ACC_PUBLIC)
222223

223224
PHP_ME(Redis, _prefix, NULL, ZEND_ACC_PUBLIC)
224225
PHP_ME(Redis, _unserialize, NULL, ZEND_ACC_PUBLIC)
@@ -6161,6 +6162,32 @@ PHP_METHOD(Redis, getLastError) {
61616162
}
61626163
}
61636164

6165+
/*
6166+
* {{{ proto Redis::clearLastError()
6167+
*/
6168+
PHP_METHOD(Redis, clearLastError) {
6169+
zval *object;
6170+
RedisSock *redis_sock;
6171+
6172+
// Grab our object
6173+
if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, redis_ce) == FAILURE) {
6174+
RETURN_FALSE;
6175+
}
6176+
// Grab socket
6177+
if(redis_sock_get(object, &redis_sock TSRMLS_CC, 0) < 0) {
6178+
RETURN_FALSE;
6179+
}
6180+
6181+
// Clear error message
6182+
if(redis_sock->err) {
6183+
efree(redis_sock->err);
6184+
}
6185+
redis_sock->err = NULL;
6186+
6187+
RETURN_TRUE;
6188+
}
6189+
6190+
61646191
/*
61656192
* {{{ proto Redis::time()
61666193
*/

tests/TestRedis.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3032,6 +3032,10 @@ public function testGetLastError() {
30323032
$incrError = $this->redis->getLastError();
30333033
$this->assertTrue($incrError !== $evalError); // error has changed
30343034
$this->assertTrue(strlen($incrError) > 0);
3035+
3036+
// clear error
3037+
$this->redis->clearLastError();
3038+
$this->assertTrue($this->redis->getLastError() === NULL);
30353039
}
30363040

30373041
// Helper function to compare nested results -- from the php.net array_diff page, I believe

0 commit comments

Comments
 (0)