Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
6e98214f
Commit
6e98214f
authored
Oct 24, 2019
by
antirez
Browse files
Modules hooks: test flush event.
parent
39f2ab59
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/module.c
View file @
6e98214f
...
@@ -5882,6 +5882,8 @@ void moduleFireServerEvent(uint64_t eid, int subid, void *data) {
...
@@ -5882,6 +5882,8 @@ void moduleFireServerEvent(uint64_t eid, int subid, void *data) {
* sense. For instance for FLUSHDB events we select the correct
* sense. For instance for FLUSHDB events we select the correct
* DB automatically. */
* DB automatically. */
selectDb
(
ctx
.
client
,
0
);
selectDb
(
ctx
.
client
,
0
);
/* Event specific context and data pointer setup. */
if
(
eid
==
REDISMODULE_EVENT_CLIENT_CHANGE
)
{
if
(
eid
==
REDISMODULE_EVENT_CLIENT_CHANGE
)
{
modulePopulateClientInfoStructure
(
&
civ1
,
data
,
modulePopulateClientInfoStructure
(
&
civ1
,
data
,
el
->
event
.
dataver
);
el
->
event
.
dataver
);
...
...
tests/modules/hooks.c
View file @
6e98214f
...
@@ -43,6 +43,7 @@ void clientChangeCallback(RedisModuleCtx *ctx, RedisModuleEvent e, uint64_t sub,
...
@@ -43,6 +43,7 @@ void clientChangeCallback(RedisModuleCtx *ctx, RedisModuleEvent e, uint64_t sub,
char
*
keyname
=
(
sub
==
REDISMODULE_SUBEVENT_CLIENT_CHANGE_CONNECTED
)
?
char
*
keyname
=
(
sub
==
REDISMODULE_SUBEVENT_CLIENT_CHANGE_CONNECTED
)
?
"connected"
:
"disconnected"
;
"connected"
:
"disconnected"
;
RedisModuleCallReply
*
reply
;
RedisModuleCallReply
*
reply
;
RedisModule_SelectDb
(
ctx
,
9
);
reply
=
RedisModule_Call
(
ctx
,
"RPUSH"
,
"cl"
,
keyname
,(
long
)
ci
->
id
);
reply
=
RedisModule_Call
(
ctx
,
"RPUSH"
,
"cl"
,
keyname
,(
long
)
ci
->
id
);
RedisModule_FreeCallReply
(
reply
);
RedisModule_FreeCallReply
(
reply
);
}
}
...
@@ -56,6 +57,7 @@ void flushdbCallback(RedisModuleCtx *ctx, RedisModuleEvent e, uint64_t sub, void
...
@@ -56,6 +57,7 @@ void flushdbCallback(RedisModuleCtx *ctx, RedisModuleEvent e, uint64_t sub, void
char
*
keyname
=
(
sub
==
REDISMODULE_SUBEVENT_FLUSHDB_START
)
?
char
*
keyname
=
(
sub
==
REDISMODULE_SUBEVENT_FLUSHDB_START
)
?
"flush-start"
:
"flush-end"
;
"flush-start"
:
"flush-end"
;
RedisModuleCallReply
*
reply
;
RedisModuleCallReply
*
reply
;
RedisModule_SelectDb
(
ctx
,
9
);
reply
=
RedisModule_Call
(
ctx
,
"RPUSH"
,
"cl"
,
keyname
,(
long
)
fi
->
dbnum
);
reply
=
RedisModule_Call
(
ctx
,
"RPUSH"
,
"cl"
,
keyname
,(
long
)
fi
->
dbnum
);
RedisModule_FreeCallReply
(
reply
);
RedisModule_FreeCallReply
(
reply
);
}
}
...
...
tests/unit/moduleapi/hooks.tcl
View file @
6e98214f
...
@@ -8,11 +8,21 @@ tags "modules" {
...
@@ -8,11 +8,21 @@ tags "modules" {
set rd1
[
redis_deferring_client
]
set rd1
[
redis_deferring_client
]
$rd1 close
$rd1 close
}
}
r select 0
puts
"Keys:
[
r keys *
]
"
assert
{[
r llen connected
]
> 1
}
assert
{[
r llen connected
]
> 1
}
assert
{[
r llen disconnected
]
> 1
}
assert
{[
r llen disconnected
]
> 1
}
}
}
test
{
Test flushdb hooks
}
{
r flushall
;
# Note: only the
"end"
RPUSH will survive
r select 1
r flushdb
r select 2
r flushdb
r select 9
assert
{[
r llen flush-start
]
== 2
}
assert
{[
r llen flush-end
]
== 3
}
assert
{[
r lrange flush-start 0 -1
]
eq
{
1 2
}}
assert
{[
r lrange flush-end 0 -1
]
eq
{
-1 1 2
}}
}
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment