Skip to content

Commit 947a2d3

Browse files
committed
Issue #1894
1 parent 77ee15c commit 947a2d3

File tree

6 files changed

+70
-2
lines changed

6 files changed

+70
-2
lines changed

redis.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,50 @@ PHP_METHOD(Redis, renameNx)
904904
}
905905
/* }}} */
906906

907+
/** {{{ proto bool Redis::reset()
908+
*/
909+
PHP_METHOD(Redis, reset)
910+
{
911+
char *response;
912+
int response_len;
913+
RedisSock *redis_sock;
914+
smart_string cmd = {0};
915+
zend_bool ret = 0;
916+
917+
if ((redis_sock = redis_sock_get(getThis(), 0)) == NULL) {
918+
RETURN_FALSE;
919+
}
920+
921+
if (IS_PIPELINE(redis_sock)) {
922+
php_error_docref(NULL, E_ERROR, "Reset ins't allowed in pipeline mode!");
923+
RETURN_FALSE;
924+
}
925+
926+
redis_cmd_init_sstr(&cmd, 0, "RESET", 5);
927+
928+
REDIS_PROCESS_REQUEST(redis_sock, cmd.c, cmd.len);
929+
930+
if ((response = redis_sock_read(redis_sock, &response_len)) != NULL) {
931+
ret = REDIS_STRCMP_STATIC(response, response_len, "+RESET");
932+
efree(response);
933+
}
934+
935+
if (!ret) {
936+
if (IS_ATOMIC(redis_sock)) {
937+
RETURN_FALSE;
938+
}
939+
REDIS_THROW_EXCEPTION("Reset failed in multi mode!", 0);
940+
RETURN_ZVAL(getThis(), 1, 0);
941+
}
942+
943+
free_reply_callbacks(redis_sock);
944+
redis_sock->status = REDIS_SOCK_STATUS_CONNECTED;
945+
redis_sock->mode = ATOMIC;
946+
redis_sock->dbNumber = 0;
947+
redis_sock->watching = 0;
948+
949+
RETURN_TRUE;
950+
}
907951
/* }}} */
908952

909953
/* {{{ proto string Redis::get(string key)

redis.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ public function rename(string $key_src, string $key_dst);
336336
/** @return bool|Redis */
337337
public function renameNx(string $key_src, string $key_dst);
338338

339+
public function reset(): bool;
340+
339341
public function restore(string $key, int $timeout, string $value): bool;
340342

341343
public function role(): mixed;

redis_arginfo.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 0475243df03f4f3d6e568fa9ae164073dadc930d */
2+
* Stub hash: 4b894d8f0c04d6c25398e5dc399598d0ede4ed05 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0)
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 0, "null")
@@ -554,6 +554,8 @@ ZEND_END_ARG_INFO()
554554

555555
#define arginfo_class_Redis_renameNx arginfo_class_Redis_rename
556556

557+
#define arginfo_class_Redis_reset arginfo_class_Redis_bgSave
558+
557559
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Redis_restore, 0, 3, _IS_BOOL, 0)
558560
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
559561
ZEND_ARG_TYPE_INFO(0, timeout, IS_LONG, 0)
@@ -1080,6 +1082,7 @@ ZEND_METHOD(Redis, randomKey);
10801082
ZEND_METHOD(Redis, rawcommand);
10811083
ZEND_METHOD(Redis, rename);
10821084
ZEND_METHOD(Redis, renameNx);
1085+
ZEND_METHOD(Redis, reset);
10831086
ZEND_METHOD(Redis, restore);
10841087
ZEND_METHOD(Redis, role);
10851088
ZEND_METHOD(Redis, rpoplpush);
@@ -1308,6 +1311,7 @@ static const zend_function_entry class_Redis_methods[] = {
13081311
ZEND_ME(Redis, rawcommand, arginfo_class_Redis_rawcommand, ZEND_ACC_PUBLIC)
13091312
ZEND_ME(Redis, rename, arginfo_class_Redis_rename, ZEND_ACC_PUBLIC)
13101313
ZEND_ME(Redis, renameNx, arginfo_class_Redis_renameNx, ZEND_ACC_PUBLIC)
1314+
ZEND_ME(Redis, reset, arginfo_class_Redis_reset, ZEND_ACC_PUBLIC)
13111315
ZEND_ME(Redis, restore, arginfo_class_Redis_restore, ZEND_ACC_PUBLIC)
13121316
ZEND_ME(Redis, role, arginfo_class_Redis_role, ZEND_ACC_PUBLIC)
13131317
ZEND_ME(Redis, rpoplpush, arginfo_class_Redis_rpoplpush, ZEND_ACC_PUBLIC)

redis_legacy_arginfo.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 0475243df03f4f3d6e568fa9ae164073dadc930d */
2+
* Stub hash: 4b894d8f0c04d6c25398e5dc399598d0ede4ed05 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0)
55
ZEND_ARG_INFO(0, options)
@@ -488,6 +488,8 @@ ZEND_END_ARG_INFO()
488488

489489
#define arginfo_class_Redis_renameNx arginfo_class_Redis_rename
490490

491+
#define arginfo_class_Redis_reset arginfo_class_Redis___destruct
492+
491493
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_restore, 0, 0, 3)
492494
ZEND_ARG_INFO(0, key)
493495
ZEND_ARG_INFO(0, timeout)
@@ -982,6 +984,7 @@ ZEND_METHOD(Redis, randomKey);
982984
ZEND_METHOD(Redis, rawcommand);
983985
ZEND_METHOD(Redis, rename);
984986
ZEND_METHOD(Redis, renameNx);
987+
ZEND_METHOD(Redis, reset);
985988
ZEND_METHOD(Redis, restore);
986989
ZEND_METHOD(Redis, role);
987990
ZEND_METHOD(Redis, rpoplpush);
@@ -1210,6 +1213,7 @@ static const zend_function_entry class_Redis_methods[] = {
12101213
ZEND_ME(Redis, rawcommand, arginfo_class_Redis_rawcommand, ZEND_ACC_PUBLIC)
12111214
ZEND_ME(Redis, rename, arginfo_class_Redis_rename, ZEND_ACC_PUBLIC)
12121215
ZEND_ME(Redis, renameNx, arginfo_class_Redis_renameNx, ZEND_ACC_PUBLIC)
1216+
ZEND_ME(Redis, reset, arginfo_class_Redis_reset, ZEND_ACC_PUBLIC)
12131217
ZEND_ME(Redis, restore, arginfo_class_Redis_restore, ZEND_ACC_PUBLIC)
12141218
ZEND_ME(Redis, role, arginfo_class_Redis_role, ZEND_ACC_PUBLIC)
12151219
ZEND_ME(Redis, rpoplpush, arginfo_class_Redis_rpoplpush, ZEND_ACC_PUBLIC)

tests/RedisClusterTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function testDoublePipeNoOp() { return $this->markTestSkipped(); }
4747
public function testSwapDB() { return $this->markTestSkipped(); }
4848
public function testConnectException() { return $this->markTestSkipped(); }
4949
public function testTlsConnect() { return $this->markTestSkipped(); }
50+
public function testReset() { return $this->markTestSkipped(); }
5051
public function testInvalidAuthArgs() { return $this->markTestSkipped(); }
5152

5253
public function testlMove() { return $this->markTestSkipped(); }

tests/RedisTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6847,6 +6847,19 @@ public function testTlsConnect()
68476847
}
68486848
}
68496849

6850+
public function testReset()
6851+
{
6852+
// Only available since 6.2.0
6853+
if (version_compare($this->version, '6.2.0') < 0) {
6854+
$this->markTestSkipped();
6855+
return;
6856+
}
6857+
6858+
$this->assertTrue($this->redis->multi()->select(2)->set('foo', 'bar')->reset());
6859+
$this->assertEquals(Redis::ATOMIC, $this->redis->getMode());
6860+
$this->assertEquals(0, $this->redis->getDBNum());
6861+
}
6862+
68506863
public function testCopy()
68516864
{
68526865
// Only available since 6.2.0

0 commit comments

Comments
 (0)