Skip to content

Commit ed7c9f6

Browse files
Implement WAITAOF command.
1 parent 142c1f4 commit ed7c9f6

14 files changed

+150
-8
lines changed

redis.c

+4
Original file line numberDiff line numberDiff line change
@@ -2178,6 +2178,10 @@ PHP_METHOD(Redis, sunsubscribe)
21782178
redis_unsubscribe_response);
21792179
}
21802180

2181+
PHP_METHOD(Redis, waitaof) {
2182+
REDIS_PROCESS_CMD(waitaof, redis_read_variant_reply);
2183+
}
2184+
21812185
/* {{{ proto string Redis::bgrewriteaof() */
21822186
PHP_METHOD(Redis, bgrewriteaof)
21832187
{

redis.stub.php

+7
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,13 @@ public function bgSave(): Redis|bool;
611611
*/
612612
public function bgrewriteaof(): Redis|bool;
613613

614+
/**
615+
* @see https://redis.io/commands/waitaof
616+
*
617+
* @return Redis|array
618+
*/
619+
public function waitaof(int $numlocal, int $numreplicas, int $timeout): Redis|array|false;
620+
614621
/**
615622
* Count the number of set bits in a Redis string.
616623
*

redis_arginfo.h

+9-1
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: 3b2ecc525884fc1ae2a71b8e053fa245b108c4bb */
2+
* Stub hash: de2f6e77cadba00b1f8312a8244db9df00a74a85 */
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, 1, "null")
@@ -49,6 +49,12 @@ ZEND_END_ARG_INFO()
4949

5050
#define arginfo_class_Redis_bgrewriteaof arginfo_class_Redis_bgSave
5151

52+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_waitaof, 0, 3, Redis, MAY_BE_ARRAY|MAY_BE_FALSE)
53+
ZEND_ARG_TYPE_INFO(0, numlocal, IS_LONG, 0)
54+
ZEND_ARG_TYPE_INFO(0, numreplicas, IS_LONG, 0)
55+
ZEND_ARG_TYPE_INFO(0, timeout, IS_LONG, 0)
56+
ZEND_END_ARG_INFO()
57+
5258
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_bitcount, 0, 1, Redis, MAY_BE_LONG|MAY_BE_FALSE)
5359
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
5460
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, start, IS_LONG, 0, "0")
@@ -1168,6 +1174,7 @@ ZEND_METHOD(Redis, append);
11681174
ZEND_METHOD(Redis, auth);
11691175
ZEND_METHOD(Redis, bgSave);
11701176
ZEND_METHOD(Redis, bgrewriteaof);
1177+
ZEND_METHOD(Redis, waitaof);
11711178
ZEND_METHOD(Redis, bitcount);
11721179
ZEND_METHOD(Redis, bitop);
11731180
ZEND_METHOD(Redis, bitpos);
@@ -1422,6 +1429,7 @@ static const zend_function_entry class_Redis_methods[] = {
14221429
ZEND_ME(Redis, auth, arginfo_class_Redis_auth, ZEND_ACC_PUBLIC)
14231430
ZEND_ME(Redis, bgSave, arginfo_class_Redis_bgSave, ZEND_ACC_PUBLIC)
14241431
ZEND_ME(Redis, bgrewriteaof, arginfo_class_Redis_bgrewriteaof, ZEND_ACC_PUBLIC)
1432+
ZEND_ME(Redis, waitaof, arginfo_class_Redis_waitaof, ZEND_ACC_PUBLIC)
14251433
ZEND_ME(Redis, bitcount, arginfo_class_Redis_bitcount, ZEND_ACC_PUBLIC)
14261434
ZEND_ME(Redis, bitop, arginfo_class_Redis_bitop, ZEND_ACC_PUBLIC)
14271435
ZEND_ME(Redis, bitpos, arginfo_class_Redis_bitpos, ZEND_ACC_PUBLIC)

redis_array_arginfo.h

+3-2
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: fa84ce2b68b10564dd8abaffecefe4dd5d65b591 */
2+
* Stub hash: 59943eeb14b3ed78f88117e6923d64a95911b5ff */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_RedisArray___call, 0, 2, IS_MIXED, 0)
55
ZEND_ARG_TYPE_INFO(0, function_name, IS_STRING, 0)
@@ -44,7 +44,8 @@ ZEND_END_ARG_INFO()
4444
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_RedisArray_discard, 0, 0, _IS_BOOL, 1)
4545
ZEND_END_ARG_INFO()
4646

47-
#define arginfo_class_RedisArray_exec arginfo_class_RedisArray_discard
47+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_RedisArray_exec, 0, 0, MAY_BE_BOOL|MAY_BE_NULL|MAY_BE_ARRAY)
48+
ZEND_END_ARG_INFO()
4849

4950
#define arginfo_class_RedisArray_flushall arginfo_class_RedisArray__continuum
5051

redis_array_legacy_arginfo.h

+1-1
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: fa84ce2b68b10564dd8abaffecefe4dd5d65b591 */
2+
* Stub hash: 59943eeb14b3ed78f88117e6923d64a95911b5ff */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisArray___call, 0, 0, 2)
55
ZEND_ARG_INFO(0, function_name)

redis_cluster.c

+47
Original file line numberDiff line numberDiff line change
@@ -2876,6 +2876,53 @@ PHP_METHOD(RedisCluster, randomkey) {
28762876
}
28772877
/* }}} */
28782878

2879+
PHP_METHOD(RedisCluster, waitaof) {
2880+
zend_long numlocal, numreplicas, timeout;
2881+
redisCluster *c = GET_CONTEXT();
2882+
smart_string cmdstr = {0};
2883+
void *ctx = NULL;
2884+
short slot;
2885+
zval *node;
2886+
2887+
ZEND_PARSE_PARAMETERS_START(4, 4)
2888+
Z_PARAM_ZVAL(node)
2889+
Z_PARAM_LONG(numlocal)
2890+
Z_PARAM_LONG(numreplicas)
2891+
Z_PARAM_LONG(timeout)
2892+
ZEND_PARSE_PARAMETERS_END();
2893+
2894+
if (numlocal < 0 || numreplicas < 0 || timeout < 0) {
2895+
php_error_docref(NULL, E_WARNING, "No arguments can be negative");
2896+
RETURN_FALSE;
2897+
}
2898+
2899+
slot = cluster_cmd_get_slot(c, node);
2900+
if (slot < 0) {
2901+
RETURN_FALSE;
2902+
}
2903+
2904+
REDIS_CMD_INIT_SSTR_STATIC(&cmdstr, 3, "WAITAOF");
2905+
redis_cmd_append_sstr_long(&cmdstr, numlocal);
2906+
redis_cmd_append_sstr_long(&cmdstr, numreplicas);
2907+
redis_cmd_append_sstr_long(&cmdstr, timeout);
2908+
2909+
c->readonly = 0;
2910+
2911+
if (cluster_send_slot(c, slot, cmdstr.c, cmdstr.len, TYPE_MULTIBULK) < 0) {
2912+
CLUSTER_THROW_EXCEPTION("Unable to send command at the specified node", 0);
2913+
smart_string_free(&cmdstr);
2914+
RETURN_FALSE;
2915+
}
2916+
2917+
if (CLUSTER_IS_ATOMIC(c)) {
2918+
cluster_variant_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, NULL);
2919+
} else {
2920+
CLUSTER_ENQUEUE_RESPONSE(c, slot, cluster_variant_resp, ctx);
2921+
}
2922+
2923+
smart_string_free(&cmdstr);
2924+
}
2925+
28792926
/* {{{ proto bool RedisCluster::ping(string key| string msg)
28802927
* proto bool RedisCluster::ping(array host_port| string msg) */
28812928
PHP_METHOD(RedisCluster, ping) {

redis_cluster.stub.php

+3
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ public function append(string $key, mixed $value): RedisCluster|bool|int;
103103
*/
104104
public function bgrewriteaof(string|array $key_or_address): RedisCluster|bool;
105105

106+
public function waitaof(string|array $key_or_address, int $numlocal,
107+
int $numreplicas, int $timeout): RedisCluster|array|false;
108+
106109
/**
107110
* @see Redis::bgsave
108111
*/

redis_cluster_arginfo.h

+10-1
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: d832720b86414896922f919bcd559fe82426c7a6 */
2+
* Stub hash: 35b71fe87bbd8df3a7495e14be957b18c3241a19 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster___construct, 0, 0, 1)
55
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 1)
@@ -56,6 +56,13 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_bgrewrite
5656
ZEND_ARG_TYPE_MASK(0, key_or_address, MAY_BE_STRING|MAY_BE_ARRAY, NULL)
5757
ZEND_END_ARG_INFO()
5858

59+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_waitaof, 0, 4, RedisCluster, MAY_BE_ARRAY|MAY_BE_FALSE)
60+
ZEND_ARG_TYPE_MASK(0, key_or_address, MAY_BE_STRING|MAY_BE_ARRAY, NULL)
61+
ZEND_ARG_TYPE_INFO(0, numlocal, IS_LONG, 0)
62+
ZEND_ARG_TYPE_INFO(0, numreplicas, IS_LONG, 0)
63+
ZEND_ARG_TYPE_INFO(0, timeout, IS_LONG, 0)
64+
ZEND_END_ARG_INFO()
65+
5966
#define arginfo_class_RedisCluster_bgsave arginfo_class_RedisCluster_bgrewriteaof
6067

6168
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_bitcount, 0, 1, RedisCluster, MAY_BE_BOOL|MAY_BE_LONG)
@@ -1047,6 +1054,7 @@ ZEND_METHOD(RedisCluster, _redir);
10471054
ZEND_METHOD(RedisCluster, acl);
10481055
ZEND_METHOD(RedisCluster, append);
10491056
ZEND_METHOD(RedisCluster, bgrewriteaof);
1057+
ZEND_METHOD(RedisCluster, waitaof);
10501058
ZEND_METHOD(RedisCluster, bgsave);
10511059
ZEND_METHOD(RedisCluster, bitcount);
10521060
ZEND_METHOD(RedisCluster, bitop);
@@ -1272,6 +1280,7 @@ static const zend_function_entry class_RedisCluster_methods[] = {
12721280
ZEND_ME(RedisCluster, acl, arginfo_class_RedisCluster_acl, ZEND_ACC_PUBLIC)
12731281
ZEND_ME(RedisCluster, append, arginfo_class_RedisCluster_append, ZEND_ACC_PUBLIC)
12741282
ZEND_ME(RedisCluster, bgrewriteaof, arginfo_class_RedisCluster_bgrewriteaof, ZEND_ACC_PUBLIC)
1283+
ZEND_ME(RedisCluster, waitaof, arginfo_class_RedisCluster_waitaof, ZEND_ACC_PUBLIC)
12751284
ZEND_ME(RedisCluster, bgsave, arginfo_class_RedisCluster_bgsave, ZEND_ACC_PUBLIC)
12761285
ZEND_ME(RedisCluster, bitcount, arginfo_class_RedisCluster_bitcount, ZEND_ACC_PUBLIC)
12771286
ZEND_ME(RedisCluster, bitop, arginfo_class_RedisCluster_bitop, ZEND_ACC_PUBLIC)

redis_cluster_legacy_arginfo.h

+10-1
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: d832720b86414896922f919bcd559fe82426c7a6 */
2+
* Stub hash: 35b71fe87bbd8df3a7495e14be957b18c3241a19 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster___construct, 0, 0, 1)
55
ZEND_ARG_INFO(0, name)
@@ -49,6 +49,13 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_bgrewriteaof, 0, 0, 1)
4949
ZEND_ARG_INFO(0, key_or_address)
5050
ZEND_END_ARG_INFO()
5151

52+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_waitaof, 0, 0, 4)
53+
ZEND_ARG_INFO(0, key_or_address)
54+
ZEND_ARG_INFO(0, numlocal)
55+
ZEND_ARG_INFO(0, numreplicas)
56+
ZEND_ARG_INFO(0, timeout)
57+
ZEND_END_ARG_INFO()
58+
5259
#define arginfo_class_RedisCluster_bgsave arginfo_class_RedisCluster_bgrewriteaof
5360

5461
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_bitcount, 0, 0, 1)
@@ -892,6 +899,7 @@ ZEND_METHOD(RedisCluster, _redir);
892899
ZEND_METHOD(RedisCluster, acl);
893900
ZEND_METHOD(RedisCluster, append);
894901
ZEND_METHOD(RedisCluster, bgrewriteaof);
902+
ZEND_METHOD(RedisCluster, waitaof);
895903
ZEND_METHOD(RedisCluster, bgsave);
896904
ZEND_METHOD(RedisCluster, bitcount);
897905
ZEND_METHOD(RedisCluster, bitop);
@@ -1117,6 +1125,7 @@ static const zend_function_entry class_RedisCluster_methods[] = {
11171125
ZEND_ME(RedisCluster, acl, arginfo_class_RedisCluster_acl, ZEND_ACC_PUBLIC)
11181126
ZEND_ME(RedisCluster, append, arginfo_class_RedisCluster_append, ZEND_ACC_PUBLIC)
11191127
ZEND_ME(RedisCluster, bgrewriteaof, arginfo_class_RedisCluster_bgrewriteaof, ZEND_ACC_PUBLIC)
1128+
ZEND_ME(RedisCluster, waitaof, arginfo_class_RedisCluster_waitaof, ZEND_ACC_PUBLIC)
11201129
ZEND_ME(RedisCluster, bgsave, arginfo_class_RedisCluster_bgsave, ZEND_ACC_PUBLIC)
11211130
ZEND_ME(RedisCluster, bitcount, arginfo_class_RedisCluster_bitcount, ZEND_ACC_PUBLIC)
11221131
ZEND_ME(RedisCluster, bitop, arginfo_class_RedisCluster_bitop, ZEND_ACC_PUBLIC)

redis_commands.c

+29-1
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ redis_fcall_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
10451045
Z_PARAM_ARRAY_HT(args)
10461046
ZEND_PARSE_PARAMETERS_END_EX(return FAILURE);
10471047

1048-
redis_cmd_init_sstr(&cmdstr, 2 + (keys ? zend_hash_num_elements(keys) : 0) +
1048+
redis_cmd_init_sstr(&cmdstr, 2 + (keys ? zend_hash_num_elements(keys) : 0) +
10491049
(args ? zend_hash_num_elements(args) : 0), kw, strlen(kw));
10501050
redis_cmd_append_sstr_zstr(&cmdstr, fn);
10511051
redis_cmd_append_sstr_long(&cmdstr, keys ? zend_hash_num_elements(keys) : 0);
@@ -2231,6 +2231,34 @@ redis_acl_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
22312231
return SUCCESS;
22322232
}
22332233

2234+
int redis_waitaof_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
2235+
char **cmd, int *cmd_len, short *slot, void **ctx)
2236+
{
2237+
zend_long numlocal, numreplicas, timeout;
2238+
smart_string cmdstr = {0};
2239+
2240+
ZEND_PARSE_PARAMETERS_START(3, 3)
2241+
Z_PARAM_LONG(numlocal)
2242+
Z_PARAM_LONG(numreplicas)
2243+
Z_PARAM_LONG(timeout)
2244+
ZEND_PARSE_PARAMETERS_END_EX(return FAILURE);
2245+
2246+
if (numlocal < 0 || numreplicas < 0 || timeout < 0) {
2247+
php_error_docref(NULL, E_WARNING, "No arguments can be negative");
2248+
return FAILURE;
2249+
}
2250+
2251+
REDIS_CMD_INIT_SSTR_STATIC(&cmdstr, 3, "WAITAOF");
2252+
redis_cmd_append_sstr_long(&cmdstr, numlocal);
2253+
redis_cmd_append_sstr_long(&cmdstr, numreplicas);
2254+
redis_cmd_append_sstr_long(&cmdstr, timeout);
2255+
2256+
*cmd = cmdstr.c;
2257+
*cmd_len = cmdstr.len;
2258+
2259+
return SUCCESS;
2260+
}
2261+
22342262
/* Attempt to pull a long expiry from a zval. We're more restrictave than zval_get_long
22352263
* because that function will return integers from things like open file descriptors
22362264
* which should simply fail as a TTL */

redis_commands.h

+3
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ int redis_geosearchstore_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock
191191
* specific processing we do (e.g. verifying subarguments) that make them
192192
* unique */
193193

194+
int redis_waitaof_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
195+
char **cmd, int *cmd_len, short *slot, void **ctx);
196+
194197
int redis_info_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
195198
char **cmd, int *cmd_len, short *slot, void **ctx);
196199

redis_legacy_arginfo.h

+9-1
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: 6afb67851068637b92e885e8a16ca6818061ed6e */
2+
* Stub hash: de2f6e77cadba00b1f8312a8244db9df00a74a85 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0)
55
ZEND_ARG_INFO(0, options)
@@ -44,6 +44,12 @@ ZEND_END_ARG_INFO()
4444

4545
#define arginfo_class_Redis_bgrewriteaof arginfo_class_Redis___destruct
4646

47+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_waitaof, 0, 0, 3)
48+
ZEND_ARG_INFO(0, numlocal)
49+
ZEND_ARG_INFO(0, numreplicas)
50+
ZEND_ARG_INFO(0, timeout)
51+
ZEND_END_ARG_INFO()
52+
4753
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_bitcount, 0, 0, 1)
4854
ZEND_ARG_INFO(0, key)
4955
ZEND_ARG_INFO(0, start)
@@ -1019,6 +1025,7 @@ ZEND_METHOD(Redis, append);
10191025
ZEND_METHOD(Redis, auth);
10201026
ZEND_METHOD(Redis, bgSave);
10211027
ZEND_METHOD(Redis, bgrewriteaof);
1028+
ZEND_METHOD(Redis, waitaof);
10221029
ZEND_METHOD(Redis, bitcount);
10231030
ZEND_METHOD(Redis, bitop);
10241031
ZEND_METHOD(Redis, bitpos);
@@ -1273,6 +1280,7 @@ static const zend_function_entry class_Redis_methods[] = {
12731280
ZEND_ME(Redis, auth, arginfo_class_Redis_auth, ZEND_ACC_PUBLIC)
12741281
ZEND_ME(Redis, bgSave, arginfo_class_Redis_bgSave, ZEND_ACC_PUBLIC)
12751282
ZEND_ME(Redis, bgrewriteaof, arginfo_class_Redis_bgrewriteaof, ZEND_ACC_PUBLIC)
1283+
ZEND_ME(Redis, waitaof, arginfo_class_Redis_waitaof, ZEND_ACC_PUBLIC)
12761284
ZEND_ME(Redis, bitcount, arginfo_class_Redis_bitcount, ZEND_ACC_PUBLIC)
12771285
ZEND_ME(Redis, bitop, arginfo_class_Redis_bitop, ZEND_ACC_PUBLIC)
12781286
ZEND_ME(Redis, bitpos, arginfo_class_Redis_bitpos, ZEND_ACC_PUBLIC)

tests/RedisClusterTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -778,5 +778,9 @@ public function testNullArray() {
778778

779779
$this->redis->setOption(Redis::OPT_NULL_MULTIBULK_AS_NULL, false);
780780
}
781+
782+
protected function execWaitAOF() {
783+
return $this->redis->waitaof(uniqid(), 0, 0, 0);
784+
}
781785
}
782786
?>

tests/RedisTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -7673,6 +7673,17 @@ public function testFunction() {
76737673
$this->assertTrue($this->redis->function('delete', 'mylib'));
76747674
}
76757675

7676+
protected function execWaitAOF() {
7677+
return $this->redis->waitaof(0, 0, 0);
7678+
}
7679+
7680+
public function testWaitAOF() {
7681+
$res = $this->execWaitAOF();
7682+
$this->assertTrue(is_array($res) && count($res) == 2 &&
7683+
isset($res[0]) && is_int($res[0]) &&
7684+
isset($res[1]) && is_int($res[1]));
7685+
}
7686+
76767687
/* Make sure we handle a bad option value gracefully */
76777688
public function testBadOptionValue() {
76787689
$this->assertFalse(@$this->redis->setOption(pow(2, 32), false));

0 commit comments

Comments
 (0)