Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpredis/phpredis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavlo Yatsukhnenko <yatsukhnenko@gmail.com>2022-04-07 21:45:31 +0300
committerPavlo Yatsukhnenko <yatsukhnenko@gmail.com>2022-04-07 21:54:14 +0300
commit750b6cf31abee1623ec494f4dbd159c4a08e4e5c (patch)
tree3f07a35bcd4a4e502a22480b01430ea480443596
parent985c738876a18da389daafa5f4611b8f9cf434f4 (diff)
Issue #1894issue-1894-flush
Add SYNC arg to FLUSHALL and FLUSHDB, and ASYNC/SYNC arg to SCRIPT FLUSH
-rw-r--r--redis.stub.php4
-rw-r--r--redis_arginfo.h4
-rw-r--r--redis_commands.c32
-rw-r--r--redis_legacy_arginfo.h4
4 files changed, 30 insertions, 14 deletions
diff --git a/redis.stub.php b/redis.stub.php
index 912eab57..52ad2e1f 100644
--- a/redis.stub.php
+++ b/redis.stub.php
@@ -117,9 +117,9 @@ class Redis {
public function expireAt(string $key, int $timestamp): bool;
- public function flushAll(bool $async = false): bool;
+ public function flushAll(?bool $sync = null): bool;
- public function flushDB(bool $async = false): bool;
+ public function flushDB(?bool $sync = null): bool;
public function geoadd(string $key, float $lng, float $lat, string $member, mixed ...$other_triples): int;
diff --git a/redis_arginfo.h b/redis_arginfo.h
index 515dacd4..be080231 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: 2f9fb51ff39db0f8e399b937728904e3283448ff */
+ * Stub hash: 0475243df03f4f3d6e568fa9ae164073dadc930d */
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")
@@ -180,7 +180,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Redis_expireAt, 0, 2, _IS_
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Redis_flushAll, 0, 0, _IS_BOOL, 0)
- ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, async, _IS_BOOL, 0, "false")
+ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, sync, _IS_BOOL, 1, "null")
ZEND_END_ARG_INFO()
#define arginfo_class_Redis_flushDB arginfo_class_Redis_flushAll
diff --git a/redis_commands.c b/redis_commands.c
index 356483d0..7d9fd88a 100644
--- a/redis_commands.c
+++ b/redis_commands.c
@@ -131,10 +131,24 @@ redis_build_script_cmd(smart_string *cmd, int argc, zval *z_args)
return NULL;
}
// Branch based on the directive
- if (!strcasecmp(Z_STRVAL(z_args[0]), "flush") || !strcasecmp(Z_STRVAL(z_args[0]), "kill")) {
- // Simple SCRIPT FLUSH, or SCRIPT_KILL command
+ if (!strcasecmp(Z_STRVAL(z_args[0]), "kill")) {
+ // Simple SCRIPT_KILL command
REDIS_CMD_INIT_SSTR_STATIC(cmd, argc, "SCRIPT");
- redis_cmd_append_sstr(cmd, Z_STRVAL(z_args[0]), Z_STRLEN(z_args[0]));
+ redis_cmd_append_sstr(cmd, "KILL", sizeof("KILL") - 1);
+ } else if (!strcasecmp(Z_STRVAL(z_args[0]), "flush")) {
+ // Simple SCRIPT FLUSH [ASYNC | SYNC]
+ if (argc > 1 && (
+ Z_TYPE(z_args[1]) != IS_STRING ||
+ strcasecmp(Z_STRVAL(z_args[1]), "sync") ||
+ strcasecmp(Z_STRVAL(z_args[1]), "async")
+ )) {
+ return NULL;
+ }
+ REDIS_CMD_INIT_SSTR_STATIC(cmd, argc, "SCRIPT");
+ redis_cmd_append_sstr(cmd, "FLUSH", sizeof("FLUSH") - 1);
+ if (argc > 1) {
+ redis_cmd_append_sstr(cmd, Z_STRVAL(z_args[1]), Z_STRLEN(z_args[1]));
+ }
} else if (!strcasecmp(Z_STRVAL(z_args[0]), "load")) {
// Make sure we have a second argument, and it's not empty. If it is
// 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,
int redis_flush_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
char *kw, char **cmd, int *cmd_len, short *slot, void **ctx)
{
- zend_bool async = 0;
+ zend_bool sync = -1;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &async) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &sync) == FAILURE) {
return FAILURE;
}
- if (async) {
- *cmd_len = REDIS_CMD_SPPRINTF(cmd, kw, "s", "ASYNC", sizeof("ASYNC") - 1);
- } else {
+ if (sync < 0) {
*cmd_len = REDIS_CMD_SPPRINTF(cmd, kw, "");
+ } else if (sync > 0) {
+ *cmd_len = REDIS_CMD_SPPRINTF(cmd, kw, "s", "SYNC", sizeof("SYNC") - 1);
+ } else {
+ *cmd_len = REDIS_CMD_SPPRINTF(cmd, kw, "s", "ASYNC", sizeof("ASYNC") - 1);
}
return SUCCESS;
diff --git a/redis_legacy_arginfo.h b/redis_legacy_arginfo.h
index 21150b10..77159f50 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: 2f9fb51ff39db0f8e399b937728904e3283448ff */
+ * Stub hash: 0475243df03f4f3d6e568fa9ae164073dadc930d */
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0)
ZEND_ARG_INFO(0, options)
@@ -168,7 +168,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_expireAt, 0, 0, 2)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_flushAll, 0, 0, 0)
- ZEND_ARG_INFO(0, async)
+ ZEND_ARG_INFO(0, sync)
ZEND_END_ARG_INFO()
#define arginfo_class_Redis_flushDB arginfo_class_Redis_flushAll