Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit54a084e

Browse files
Refactor FLUSHDB and update docs.
Fixes#2096
1 parent457953f commit54a084e

File tree

8 files changed

+58
-18
lines changed

8 files changed

+58
-18
lines changed

‎README.markdown‎

Lines 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‎

Lines 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
#defineZ_PARAM_ZVAL_OR_NULL(dest) \
155155
Z_PARAM_ZVAL_EX(dest, 1, 0)
156+
#defineZ_PARAM_BOOL_OR_NULL(dest,is_null) \
157+
Z_PARAM_BOOL_EX(dest, is_null, 1, 0)
156158
#endif
157159

158160
#ifPHPREDIS_DEBUG_LOGGING==1

‎redis.stub.php‎

Lines 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
publicfunctionpexpiretime(string$key):Redis|int|false;
134134

135-
publicfunctionflushAll(?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+
publicfunctionflushAll(?bool$sync =null):Redis|bool;
136146

137-
publicfunctionflushDB(?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+
publicfunctionflushDB(?bool$sync =null):Redis|bool;
138158

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

‎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: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
#definearginfo_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‎

Lines 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
intredis_flush_cmd(INTERNAL_FUNCTION_PARAMETERS,RedisSock*redis_sock,
530530
char*kw,char**cmd,int*cmd_len,short*slot,void**ctx)
531531
{
532-
intsync=-1;
532+
smart_stringcmdstr= {0};
533+
zend_boolsync=0;
534+
zend_boolis_null=1;
533535

534-
if (zend_parse_parameters(ZEND_NUM_ARGS(),"|b",&sync)==FAILURE) {
535-
returnFAILURE;
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(returnFAILURE);
537540

538-
if (sync<0) {
539-
*cmd_len=REDIS_CMD_SPPRINTF(cmd,kw,"");
540-
}elseif (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
returnSUCCESS;
547555
}
548556

‎redis_legacy_arginfo.h‎

Lines 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‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function testGeoSearch() { return $this->marktestSkipped(); }
6565
publicfunctiontestGeoSearchStore() {return$this->marktestSkipped(); }
6666
publicfunctiontestHRandField() {return$this->marktestSkipped(); }
6767
publicfunctiontestConfig() {return$this->markTestSkipped(); }
68+
publicfunctiontestFlushDB() {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‎

Lines 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+
publicfunctiontestFlushDB() {
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
publicfunctiontestttl() {
21642171
$this->redis->set('x','y');
21652172
$this->redis->expire('x',5);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp