Skip to content

Commit 750b6cf

Browse files
committed
Issue #1894
Add SYNC arg to FLUSHALL and FLUSHDB, and ASYNC/SYNC arg to SCRIPT FLUSH
1 parent 985c738 commit 750b6cf

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

redis.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ public function expire(string $key, int $timeout): bool;
117117

118118
public function expireAt(string $key, int $timestamp): bool;
119119

120-
public function flushAll(bool $async = false): bool;
120+
public function flushAll(?bool $sync = null): bool;
121121

122-
public function flushDB(bool $async = false): bool;
122+
public function flushDB(?bool $sync = null): bool;
123123

124124
public function geoadd(string $key, float $lng, float $lat, string $member, mixed ...$other_triples): int;
125125

redis_arginfo.h

Lines changed: 2 additions & 2 deletions
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: 2f9fb51ff39db0f8e399b937728904e3283448ff */
2+
* Stub hash: 0475243df03f4f3d6e568fa9ae164073dadc930d */
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")
@@ -180,7 +180,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Redis_expireAt, 0, 2, _IS_
180180
ZEND_END_ARG_INFO()
181181

182182
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Redis_flushAll, 0, 0, _IS_BOOL, 0)
183-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, async, _IS_BOOL, 0, "false")
183+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, sync, _IS_BOOL, 1, "null")
184184
ZEND_END_ARG_INFO()
185185

186186
#define arginfo_class_Redis_flushDB arginfo_class_Redis_flushAll

redis_commands.c

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,24 @@ redis_build_script_cmd(smart_string *cmd, int argc, zval *z_args)
131131
return NULL;
132132
}
133133
// Branch based on the directive
134-
if (!strcasecmp(Z_STRVAL(z_args[0]), "flush") || !strcasecmp(Z_STRVAL(z_args[0]), "kill")) {
135-
// Simple SCRIPT FLUSH, or SCRIPT_KILL command
134+
if (!strcasecmp(Z_STRVAL(z_args[0]), "kill")) {
135+
// Simple SCRIPT_KILL command
136136
REDIS_CMD_INIT_SSTR_STATIC(cmd, argc, "SCRIPT");
137-
redis_cmd_append_sstr(cmd, Z_STRVAL(z_args[0]), Z_STRLEN(z_args[0]));
137+
redis_cmd_append_sstr(cmd, "KILL", sizeof("KILL") - 1);
138+
} else if (!strcasecmp(Z_STRVAL(z_args[0]), "flush")) {
139+
// Simple SCRIPT FLUSH [ASYNC | SYNC]
140+
if (argc > 1 && (
141+
Z_TYPE(z_args[1]) != IS_STRING ||
142+
strcasecmp(Z_STRVAL(z_args[1]), "sync") ||
143+
strcasecmp(Z_STRVAL(z_args[1]), "async")
144+
)) {
145+
return NULL;
146+
}
147+
REDIS_CMD_INIT_SSTR_STATIC(cmd, argc, "SCRIPT");
148+
redis_cmd_append_sstr(cmd, "FLUSH", sizeof("FLUSH") - 1);
149+
if (argc > 1) {
150+
redis_cmd_append_sstr(cmd, Z_STRVAL(z_args[1]), Z_STRLEN(z_args[1]));
151+
}
138152
} else if (!strcasecmp(Z_STRVAL(z_args[0]), "load")) {
139153
// Make sure we have a second argument, and it's not empty. If it is
140154
// empty, we can just return an empty array (which is what Redis does)
@@ -436,16 +450,18 @@ int redis_key_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
436450
int redis_flush_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
437451
char *kw, char **cmd, int *cmd_len, short *slot, void **ctx)
438452
{
439-
zend_bool async = 0;
453+
zend_bool sync = -1;
440454

441-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &async) == FAILURE) {
455+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &sync) == FAILURE) {
442456
return FAILURE;
443457
}
444458

445-
if (async) {
446-
*cmd_len = REDIS_CMD_SPPRINTF(cmd, kw, "s", "ASYNC", sizeof("ASYNC") - 1);
447-
} else {
459+
if (sync < 0) {
448460
*cmd_len = REDIS_CMD_SPPRINTF(cmd, kw, "");
461+
} else if (sync > 0) {
462+
*cmd_len = REDIS_CMD_SPPRINTF(cmd, kw, "s", "SYNC", sizeof("SYNC") - 1);
463+
} else {
464+
*cmd_len = REDIS_CMD_SPPRINTF(cmd, kw, "s", "ASYNC", sizeof("ASYNC") - 1);
449465
}
450466

451467
return SUCCESS;

redis_legacy_arginfo.h

Lines changed: 2 additions & 2 deletions
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: 2f9fb51ff39db0f8e399b937728904e3283448ff */
2+
* Stub hash: 0475243df03f4f3d6e568fa9ae164073dadc930d */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0)
55
ZEND_ARG_INFO(0, options)
@@ -168,7 +168,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_expireAt, 0, 0, 2)
168168
ZEND_END_ARG_INFO()
169169

170170
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_flushAll, 0, 0, 0)
171-
ZEND_ARG_INFO(0, async)
171+
ZEND_ARG_INFO(0, sync)
172172
ZEND_END_ARG_INFO()
173173

174174
#define arginfo_class_Redis_flushDB arginfo_class_Redis_flushAll

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy