diff options
author | Pavlo Yatsukhnenko <yatsukhnenko@users.noreply.github.com> | 2022-04-11 22:11:31 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-11 22:11:31 +0300 |
commit | c65772fb4d954933a503494b5d5413c3948ece6a (patch) | |
tree | 062d5fbdc10730806098af4a11a67ba922a3fe4d | |
parent | 77ee15c243933c2f279babed8b32c6b65aa12421 (diff) | |
parent | 947a2d3897f2be2d51fb4672c351df9835724e78 (diff) |
Merge pull request #2092 from phpredis/issue-1894-reset
Issue #1894
-rw-r--r-- | redis.c | 44 | ||||
-rw-r--r-- | redis.stub.php | 2 | ||||
-rw-r--r-- | redis_arginfo.h | 6 | ||||
-rw-r--r-- | redis_legacy_arginfo.h | 6 | ||||
-rw-r--r-- | tests/RedisClusterTest.php | 1 | ||||
-rw-r--r-- | tests/RedisTest.php | 13 |
6 files changed, 70 insertions, 2 deletions
@@ -904,6 +904,50 @@ PHP_METHOD(Redis, renameNx) } /* }}} */ +/** {{{ proto bool Redis::reset() + */ +PHP_METHOD(Redis, reset) +{ + char *response; + int response_len; + RedisSock *redis_sock; + smart_string cmd = {0}; + zend_bool ret = 0; + + if ((redis_sock = redis_sock_get(getThis(), 0)) == NULL) { + RETURN_FALSE; + } + + if (IS_PIPELINE(redis_sock)) { + php_error_docref(NULL, E_ERROR, "Reset ins't allowed in pipeline mode!"); + RETURN_FALSE; + } + + redis_cmd_init_sstr(&cmd, 0, "RESET", 5); + + REDIS_PROCESS_REQUEST(redis_sock, cmd.c, cmd.len); + + if ((response = redis_sock_read(redis_sock, &response_len)) != NULL) { + ret = REDIS_STRCMP_STATIC(response, response_len, "+RESET"); + efree(response); + } + + if (!ret) { + if (IS_ATOMIC(redis_sock)) { + RETURN_FALSE; + } + REDIS_THROW_EXCEPTION("Reset failed in multi mode!", 0); + RETURN_ZVAL(getThis(), 1, 0); + } + + free_reply_callbacks(redis_sock); + redis_sock->status = REDIS_SOCK_STATUS_CONNECTED; + redis_sock->mode = ATOMIC; + redis_sock->dbNumber = 0; + redis_sock->watching = 0; + + RETURN_TRUE; +} /* }}} */ /* {{{ proto string Redis::get(string key) diff --git a/redis.stub.php b/redis.stub.php index 52ad2e1f..03183817 100644 --- a/redis.stub.php +++ b/redis.stub.php @@ -336,6 +336,8 @@ public function persist(string $key): bool; /** @return bool|Redis */ public function renameNx(string $key_src, string $key_dst); + public function reset(): bool; + public function restore(string $key, int $timeout, string $value): bool; public function role(): mixed; diff --git a/redis_arginfo.h b/redis_arginfo.h index be080231..786c2547 100644 --- a/redis_arginfo.h +++ b/redis_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 0475243df03f4f3d6e568fa9ae164073dadc930d */ + * Stub hash: 4b894d8f0c04d6c25398e5dc399598d0ede4ed05 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 0, "null") @@ -554,6 +554,8 @@ ZEND_END_ARG_INFO() #define arginfo_class_Redis_renameNx arginfo_class_Redis_rename +#define arginfo_class_Redis_reset arginfo_class_Redis_bgSave + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Redis_restore, 0, 3, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, timeout, IS_LONG, 0) @@ -1080,6 +1082,7 @@ ZEND_METHOD(Redis, randomKey); ZEND_METHOD(Redis, rawcommand); ZEND_METHOD(Redis, rename); ZEND_METHOD(Redis, renameNx); +ZEND_METHOD(Redis, reset); ZEND_METHOD(Redis, restore); ZEND_METHOD(Redis, role); ZEND_METHOD(Redis, rpoplpush); @@ -1308,6 +1311,7 @@ static const zend_function_entry class_Redis_methods[] = { ZEND_ME(Redis, rawcommand, arginfo_class_Redis_rawcommand, ZEND_ACC_PUBLIC) ZEND_ME(Redis, rename, arginfo_class_Redis_rename, ZEND_ACC_PUBLIC) ZEND_ME(Redis, renameNx, arginfo_class_Redis_renameNx, ZEND_ACC_PUBLIC) + ZEND_ME(Redis, reset, arginfo_class_Redis_reset, ZEND_ACC_PUBLIC) ZEND_ME(Redis, restore, arginfo_class_Redis_restore, ZEND_ACC_PUBLIC) ZEND_ME(Redis, role, arginfo_class_Redis_role, ZEND_ACC_PUBLIC) ZEND_ME(Redis, rpoplpush, arginfo_class_Redis_rpoplpush, ZEND_ACC_PUBLIC) diff --git a/redis_legacy_arginfo.h b/redis_legacy_arginfo.h index 77159f50..39890355 100644 --- a/redis_legacy_arginfo.h +++ b/redis_legacy_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 0475243df03f4f3d6e568fa9ae164073dadc930d */ + * Stub hash: 4b894d8f0c04d6c25398e5dc399598d0ede4ed05 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0) ZEND_ARG_INFO(0, options) @@ -488,6 +488,8 @@ ZEND_END_ARG_INFO() #define arginfo_class_Redis_renameNx arginfo_class_Redis_rename +#define arginfo_class_Redis_reset arginfo_class_Redis___destruct + ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_restore, 0, 0, 3) ZEND_ARG_INFO(0, key) ZEND_ARG_INFO(0, timeout) @@ -982,6 +984,7 @@ ZEND_METHOD(Redis, randomKey); ZEND_METHOD(Redis, rawcommand); ZEND_METHOD(Redis, rename); ZEND_METHOD(Redis, renameNx); +ZEND_METHOD(Redis, reset); ZEND_METHOD(Redis, restore); ZEND_METHOD(Redis, role); ZEND_METHOD(Redis, rpoplpush); @@ -1210,6 +1213,7 @@ static const zend_function_entry class_Redis_methods[] = { ZEND_ME(Redis, rawcommand, arginfo_class_Redis_rawcommand, ZEND_ACC_PUBLIC) ZEND_ME(Redis, rename, arginfo_class_Redis_rename, ZEND_ACC_PUBLIC) ZEND_ME(Redis, renameNx, arginfo_class_Redis_renameNx, ZEND_ACC_PUBLIC) + ZEND_ME(Redis, reset, arginfo_class_Redis_reset, ZEND_ACC_PUBLIC) ZEND_ME(Redis, restore, arginfo_class_Redis_restore, ZEND_ACC_PUBLIC) ZEND_ME(Redis, role, arginfo_class_Redis_role, ZEND_ACC_PUBLIC) ZEND_ME(Redis, rpoplpush, arginfo_class_Redis_rpoplpush, ZEND_ACC_PUBLIC) diff --git a/tests/RedisClusterTest.php b/tests/RedisClusterTest.php index f491e92a..6ca5153d 100644 --- a/tests/RedisClusterTest.php +++ b/tests/RedisClusterTest.php @@ -47,6 +47,7 @@ class Redis_Cluster_Test extends Redis_Test { public function testSwapDB() { return $this->markTestSkipped(); } public function testConnectException() { return $this->markTestSkipped(); } public function testTlsConnect() { return $this->markTestSkipped(); } + public function testReset() { return $this->markTestSkipped(); } public function testInvalidAuthArgs() { return $this->markTestSkipped(); } public function testlMove() { return $this->markTestSkipped(); } diff --git a/tests/RedisTest.php b/tests/RedisTest.php index 6a5f4153..8c79d6be 100644 --- a/tests/RedisTest.php +++ b/tests/RedisTest.php @@ -6847,6 +6847,19 @@ class Redis_Test extends TestSuite } } + public function testReset() + { + // Only available since 6.2.0 + if (version_compare($this->version, '6.2.0') < 0) { + $this->markTestSkipped(); + return; + } + + $this->assertTrue($this->redis->multi()->select(2)->set('foo', 'bar')->reset()); + $this->assertEquals(Redis::ATOMIC, $this->redis->getMode()); + $this->assertEquals(0, $this->redis->getDBNum()); + } + public function testCopy() { // Only available since 6.2.0 |