8000 Implement `GETDEL` for `RedisCluster` · phpredis/phpredis@d342e4a · GitHub
[go: up one dir, main page]

Skip to content

Commit d342e4a

Browse files
Implement GETDEL for RedisCluster
Fixes #2629
1 parent 36ab585 commit d342e4a

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

redis_cluster.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@ PHP_METHOD(RedisCluster, get) {
287287
}
288288
/* }}} */
289289

290+
/* {{{ proto string RedisCluster::getdel(string key) */
291+
PHP_METHOD(RedisCluster, getdel) {
292+
CLUSTER_PROCESS_KW_CMD("GETDEL", redis_key_cmd, cluster_bulk_resp, 1);
293+
}
294+
/* }}} */
295+
290296
/* {{{ proto array|false RedisCluster::getWithMeta(string key) */
291297
PHP_METHOD(RedisCluster, getWithMeta) {
292298
redisCluster *c = GET_CONTEXT();

redis_cluster.stub.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,11 @@ public function geosearchstore(string $dst, string $src, array|string $position,
390390
*/
391391
public function get(string $key): mixed;
392392

393+
/**
394+
* @see Redis::getdel
395+
*/
396+
public function getdel(string $key): mixed;
397+
393398
/**
394399
* @see Redis::getWithMeta
395400
*/

redis_cluster_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: 5966b99fd578eca94880e09539542edfbcbcdaed */
2+
* Stub hash: 43a43fa735ced4b48a361078ac8a10fb62cb1244 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster___construct, 0, 0, 1)
55
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 1)
@@ -325,6 +325,8 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_RedisCluster_get, 0, 1, IS
325325
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
326326
ZEND_END_ARG_INFO()
327327

328+
#define arginfo_class_RedisCluster_getdel arginfo_class_RedisCluster_get
329+
328330
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_getWithMeta, 0, 1, RedisCluster, MAY_BE_ARRAY|MAY_BE_FALSE)
329331
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
330332
ZEND_END_ARG_INFO()
@@ -1129,6 +1131,7 @@ ZEND_METHOD(RedisCluster, georadiusbymember_ro);
11291131
ZEND_METHOD(RedisCluster, geosearch);
11301132
ZEND_METHOD(RedisCluster, geosearchstore);
11311133
ZEND_METHOD(RedisCluster, get);
1134+
ZEND_METHOD(RedisCluster, getdel);
11321135
ZEND_METHOD(RedisCluster, getWithMeta);
11331136
ZEND_METHOD(RedisCluster, getex);
11341137
ZEND_METHOD(RedisCluster, getbit);
@@ -1359,6 +1362,7 @@ static const zend_function_entry class_RedisCluster_methods[] = {
13591362
ZEND_ME(RedisCluster, geosearch, arginfo_class_RedisCluster_geosearch, ZEND_ACC_PUBLIC)
13601363
ZEND_ME(RedisCluster, geosearchstore, arginfo_class_RedisCluster_geosearchstore, ZEND_ACC_PUBLIC)
13611364
ZEND_ME(RedisCluster, get, arginfo_class_RedisCluster_get, ZEND_ACC_PUBLIC)
1365+
ZEND_ME(RedisCluster, getdel, arginfo_class_RedisCluster_getdel, ZEND_ACC_PUBLIC)
13621366
ZEND_ME(RedisCluster, getWithMeta, arginfo_class_RedisCluster_getWithMeta, ZEND_ACC_PUBLIC)
13631367
ZEND_ME(RedisCluster, getex, arginfo_class_RedisCluster_getex, ZEND_ACC_PUBLIC)
13641368
ZEND_ME(RedisCluster, getbit, arginfo_class_RedisCluster_getbit, ZEND_ACC_PUBLIC)

redis_cluster_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: 5966b99fd578eca94880e09539542edfbcbcdaed */
2+
* Stub hash: 43a43fa735ced4b48a361078ac8a10fb62cb1244 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster___construct, 0, 0, 1)
55
ZEND_ARG_INFO(0, name)
@@ -295,6 +295,8 @@ ZEND_END_ARG_INFO()
295295

296296
#define arginfo_class_RedisCluster_get arginfo_class_RedisCluster__prefix
297297

298+
#define arginfo_class_RedisCluster_getdel arginfo_class_RedisCluster__prefix
299+
298300
#define arginfo_class_RedisCluster_getWithMeta arginfo_class_RedisCluster__prefix
299301

300302
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_getex, 0, 0, 1)
@@ -971,6 +973,7 @@ ZEND_METHOD(RedisCluster, georadiusbymember_ro);
971973
ZEND_METHOD(RedisCluster, geosearch);
972974
ZEND_METHOD(RedisCluster, geosearchstore);
973975
ZEND_METHOD(RedisCluster, get);
976+
ZEND_METHOD(RedisCluster, getdel);
974977
ZEND_METHOD(RedisCluster, getWithMeta);
975978
ZEND_METHOD(RedisCluster, getex);
976979
ZEND_METHOD(RedisCluster, getbit);
@@ -1201,6 +1204,7 @@ static const zend_function_entry class_RedisCluster_methods[] = {
12011204
ZEND_ME(RedisCluster, geosearch, arginfo_class_RedisCluster_geosearch, ZEND_ACC_PUBLIC)
12021205
ZEND_ME(RedisCluster, geosearchstore, arginfo_class_RedisCluster_geosearchstore, ZEND_ACC_PUBLIC)
12031206
ZEND_ME(RedisCluster, get, arginfo_class_RedisCluster_get, ZEND_ACC_PUBLIC)
1207+
ZEND_ME(RedisCluster, getdel, arginfo_class_RedisCluster_getdel, ZEND_ACC_PUBLIC)
12041208
ZEND_ME(RedisCluster, getWithMeta, arginfo_class_RedisCluster_getWithMeta, ZEND_ACC_PUBLIC)
12051209
ZEND_ME(RedisCluster, getex, arginfo_class_RedisCluster_getex, ZEND_ACC_PUBLIC)
12061210
ZEND_ME(RedisCluster, getbit, arginfo_class_RedisCluster_getbit, ZEND_ACC_PUBLIC)

tests/RedisTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,13 @@ public function testGetSet() {
654654
$this->assertEquals('123', $this->redis->getSet('key', '123'));
655655
}
656656

657+
public function testGetDel() {
658+
$this->redis->del('key');
659+
$this->assertTrue($this->redis->set('key', 'iexist'));
660+
$this->assertEquals('iexist', $this->redis->getDel('key'));
661+
$this->assertEquals(0, $this->redis->exists('key'));
662+
}
663+
657664
public function testRandomKey() {
658665
for ($i = 0; $i < 1000; $i++) {
659666
$k = $this->redis->randomKey();

0 commit comments

Comments
 (0)
0