Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 54a084e

Browse filesBrowse files
Refactor FLUSHDB and update docs.
Fixes #2096
1 parent 457953f commit 54a084e
Copy full SHA for 54a084e

8 files changed

+58
-18
lines changed

‎README.markdown

Copy file name to clipboardExpand all lines: README.markdown
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -608,11 +608,13 @@ $redis->flushAll();
608608
-----
609609
_**Description**_: Remove all keys from the current database.
610610

611-
##### *Parameters*
612-
*async* (bool) requires server version 4.0.0 or greater
611+
##### *Prototype*
612+
~~~php
613+
$redis->flushdb(?bool $sync = NULL): Redis|bool;
614+
~~~
613615

614616
##### *Return value*
615-
*BOOL*: Always `TRUE`.
617+
*BOOL*: This command returns true on success and false on failure.
616618

617619
##### *Example*
618620
~~~php

‎common.h

Copy file name to clipboardExpand all lines: common.h
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ typedef enum {
153153
Z_PARAM_STR_EX(dest, 1, 0)
154154
#define Z_PARAM_ZVAL_OR_NULL(dest) \
155155
Z_PARAM_ZVAL_EX(dest, 1, 0)
156+
#define Z_PARAM_BOOL_OR_NULL(dest, is_null) \
157+
Z_PARAM_BOOL_EX(dest, is_null, 1, 0)
156158
#endif
157159

158160
#if PHPREDIS_DEBUG_LOGGING == 1

‎redis.stub.php

Copy file name to clipboardExpand all lines: redis.stub.php
+22-2Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,29 @@ public function expiretime(string $key): Redis|int|false;
132132

133133
public function pexpiretime(string $key): Redis|int|false;
134134

135-
public function flushAll(?bool $sync = null): bool;
135+
/**
136+
* Deletes every key in all Redis databases
137+
*
138+
* @param bool $sync Whether to perform the task in a blocking or non-blocking way.
139+
* when TRUE, PhpRedis will execute `FLUSHALL SYNC`, and when FALSE we
140+
* will execute `FLUSHALL ASYNC`. If the argument is omitted, we
141+
* simply execute `FLUSHALL` and whether it is SYNC or ASYNC depends
142+
* on Redis' `lazyfree-lazy-user-flush` config setting.
143+
* @return bool
144+
*/
145+
public function flushAll(?bool $sync = null): Redis|bool;
136146

137-
public function flushDB(?bool $sync = null): bool;
147+
/**
148+
* Deletes all the keys of the currently selected database.
149+
*
150+
* @param bool $sync Whether to perform the task in a blocking or non-blocking way.
151+
* when TRUE, PhpRedis will execute `FLUSHDB SYNC`, and when FALSE we
152+
* will execute `FLUSHDB ASYNC`. If the argument is omitted, we
153+
* simply execute `FLUSHDB` and whether it is SYNC or ASYNC depends
154+
* on Redis' `lazyfree-lazy-user-flush` config setting.
155+
* @return bool
156+
*/
157+
public function flushDB(?bool $sync = null): Redis|bool;
138158

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

‎redis_arginfo.h

Copy file name to clipboardExpand all lines: redis_arginfo.h
+2-2Lines 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: 73e34ca5d2f49dd1dbcbf901d3dd48019e1ba5dc */
2+
* Stub hash: c9de2943a9517d8007381f36a47ab45ef911ae67 */
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")
@@ -217,7 +217,7 @@ ZEND_END_ARG_INFO()
217217

218218
#define arginfo_class_Redis_pexpiretime arginfo_class_Redis_expiretime
219219

220-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Redis_flushAll, 0, 0, _IS_BOOL, 0)
220+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_flushAll, 0, 0, Redis, MAY_BE_BOOL)
221221
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, sync, _IS_BOOL, 1, "null")
222222
ZEND_END_ARG_INFO()
223223

‎redis_commands.c

Copy file name to clipboardExpand all lines: redis_commands.c
+18-10Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -529,20 +529,28 @@ redis_failover_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
529529
int redis_flush_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
530530
char *kw, char **cmd, int *cmd_len, short *slot, void **ctx)
531531
{
532-
int sync = -1;
532+
smart_string cmdstr = {0};
533+
zend_bool sync = 0;
534+
zend_bool is_null = 1;
533535

534-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &sync) == FAILURE) {
535-
return FAILURE;
536-
}
536+
ZEND_PARSE_PARAMETERS_START(0, 1)
537+
Z_PARAM_OPTIONAL
538+
Z_PARAM_BOOL_OR_NULL(sync, is_null)
539+
ZEND_PARSE_PARAMETERS_END_EX(return FAILURE);
537540

538-
if (sync < 0) {
539-
*cmd_len = REDIS_CMD_SPPRINTF(cmd, kw, "");
540-
} else if (sync > 0) {
541-
*cmd_len = REDIS_CMD_SPPRINTF(cmd, kw, "s", "SYNC", sizeof("SYNC") - 1);
542-
} else {
543-
*cmd_len = REDIS_CMD_SPPRINTF(cmd, kw, "s", "ASYNC", sizeof("ASYNC") - 1);
541+
redis_cmd_init_sstr(&cmdstr, !is_null, kw, strlen(kw));
542+
if (!is_null) {
543+
ZEND_ASSERT(sync == 0 || sync == 1);
544+
if (sync == 0) {
545+
REDIS_CMD_APPEND_SSTR_STATIC(&cmdstr, "ASYNC");
546+
} else {
547+
REDIS_CMD_APPEND_SSTR_STATIC(&cmdstr, "SYNC");
548+
}
544549
}
545550

551+
*cmd = cmdstr.c;
552+
*cmd_len = cmdstr.len;
553+
546554
return SUCCESS;
547555
}
548556

‎redis_legacy_arginfo.h

Copy file name to clipboardExpand all lines: redis_legacy_arginfo.h
+1-1Lines changed: 1 addition & 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: 73e34ca5d2f49dd1dbcbf901d3dd48019e1ba5dc */
2+
* Stub hash: c9de2943a9517d8007381f36a47ab45ef911ae67 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0)
55
ZEND_ARG_INFO(0, options)

‎tests/RedisClusterTest.php

Copy file name to clipboardExpand all lines: tests/RedisClusterTest.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function testGeoSearch() { return $this->marktestSkipped(); }
6565
public function testGeoSearchStore() { return $this->marktestSkipped(); }
6666
public function testHRandField() { return $this->marktestSkipped(); }
6767
public function testConfig() { return $this->markTestSkipped(); }
68+
public function testFlushDB() { return $this->markTestSkipped(); }
6869

6970
/* Session locking feature is currently not supported in in context of Redis Cluster.
7071
The biggest issue for this is the distribution nature of Redis cluster */

‎tests/RedisTest.php

Copy file name to clipboardExpand all lines: tests/RedisTest.php
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,6 +2160,13 @@ public function testdbSize() {
21602160
$this->assertTrue($this->redis->dbSize() === 1);
21612161
}
21622162

2163+
public function testFlushDB() {
2164+
$this->assertTrue($this->redis->flushdb());
2165+
$this->assertTrue($this->redis->flushdb(NULL));
2166+
$this->assertTrue($this->redis->flushdb(false));
2167+
$this->assertTrue($this->redis->flushdb(true));
2168+
}
2169+
21632170
public function testttl() {
21642171
$this->redis->set('x', 'y');
21652172
$this->redis->expire('x', 5);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.